Sample code for 30+ languages & platforms
Dart Requires Chilkat v11.6.0+

Azure Table: Retry a Read with Bounded Backoff

See more Azure Table Service Examples

Retries only this GET for selected transient HTTP statuses, at most five attempts. Uses exponential backoff plus jitter and honors numeric or HTTP-date Retry-After without shortening a requested wait. Stops when the server asks for more than 30 seconds, on invalid Retry-After, authentication failures or transport errors. Each connection/read also has a timeout. This is not a generic write-retry policy; uncertain mutation outcomes require reconciliation.

Targets Azure Storage Table service in the public cloud, not Azure Cosmos DB for Table. Uses Chilkat 11.6.0 or later and an unlocked library. Direct data requests pin x-ms-version 2026-04-06 and OData 3.0. Shared Key examples read private qa_data/azure/storage.json with account and access_key string fields. Authentication examples explain their additional fields. Create private local directories before running; keep credentials, tokens, SAS, entity values, checkpoints and diagnostics outside public content and source control.

HTTPS certificates are verified. Transport completion and HTTP status are checked separately. Writes are not automatically retried after an uncertain outcome. Entity keys, ETags and continuation tokens remain strings. Examples operate on the existing ExampleCustomers table unless noted; review the targets before adapting them. Microsoft Entra ID with suitable Table data roles is preferred where available.

Microsoft reference.

Chilkat Dart Downloads

Dart
import 'package:chilkat/chilkat.dart';

void main() {
  // StringBuilder compares text by value in every generated language.
  final textCompare = CkStringBuilder();
  // Assumes Chilkat is unlocked. See Global Unlock Sample.
  final config = CkJsonObject();
  config.strict = true;
  try {
    config.loadFile('qa_data/azure/storage.json');
  } on ChilkatException {
    print('Could not load private Azure configuration.');
    return;
  }

  textCompare.clear();
  textCompare.setString(config.stringOf('account'));
  final sameText1 = textCompare.contentsEqual('', true);
  if ((config.jsonTypeOf('account') != 1) || (sameText1)) {
    print('Supply the storage account name.');
    return;
  }

  // access_key is the base64 account key, not a connection string or SAS.
  textCompare.clear();
  textCompare.setString(config.stringOf('access_key'));
  final sameText2 = textCompare.contentsEqual('', true);
  if ((config.jsonTypeOf('access_key') != 1) || (sameText2)) {
    print('Supply the base64 account access key.');
    return;
  }

  final accountText = CkStringBuilder();
  try {
    accountText.append(config.stringOf('account'));
  } on ChilkatException {
    print('Could not prepare the request.');
    return;
  }

  if ((accountText.length < 3) || (accountText.length > 24)) {
    print('Storage account names need 3-24 lowercase letters or digits.');
    return;
  }

  final allowedAccountChars = CkStringBuilder();
  try {
    allowedAccountChars.append('abcdefghijklmnopqrstuvwxyz0123456789');
  } on ChilkatException {
    print('Could not prepare the request.');
    return;
  }

  var charIndex = 0;
  while (charIndex < accountText.length) {
    if (!allowedAccountChars.contains(accountText.getRange(charIndex, 1, false), true)) {
      print('Storage account names need lowercase letters or digits.');
      return;
    }

    charIndex++;
  }

  final endpoint = CkStringBuilder();
  try {
    endpoint.append(config.stringOf('account'));
  } on ChilkatException {
    print('Could not prepare the request.');
    return;
  }

  try {
    endpoint.append('.table.core.windows.net');
  } on ChilkatException {
    print('Could not prepare the request.');
    return;
  }

  // Table names contain only letters and digits and are case-insensitive.
  // Entity PartitionKey and RowKey values are case-sensitive.
  var resourcePath = '/ExampleCustomers()';
  final rest = CkRest();
  rest.connectTimeoutMs = 20000;
  rest.idleTimeoutMs = 60000;
  final azAuth = CkAuthAzureStorage();
  azAuth.account = config.stringOf('account');
  azAuth.accessKey = config.stringOf('access_key');
  azAuth.service = 'Table';
  azAuth.scheme = 'SharedKey';
  azAuth.xMsVersion = '2026-04-06';
  try {
    rest.setAuthAzureStorage(azAuth);
  } on ChilkatException {
    print('Could not configure Shared Key signing.');
    return;
  }

  final connection = CkSocket();
  connection.requireSslCertVerify = true;
  connection.maxReadIdleMs = 60000;
  connection.maxSendIdleMs = 60000;
  try {
    connection.connect(endpoint.getAsString(), 443, true, 20000);
  } on ChilkatException {
    print('TLS connection failed; inspect diagnostics privately.');
    return;
  }

  // Do not replay a write automatically after losing its response.
  try {
    rest.useConnection(connection, false);
  } on ChilkatException {
    print('Could not prepare the request.');
    return;
  }

  var responseText = '';
  final result = CkJsonObject();
  result.strict = true;
  try {
    rest.addHeader('DataServiceVersion', '3.0;NetFx');
  } on ChilkatException {
    print('Could not prepare the request.');
    return;
  }

  try {
    rest.addHeader('MaxDataServiceVersion', '3.0;NetFx');
  } on ChilkatException {
    print('Could not prepare the request.');
    return;
  }

  try {
    rest.addHeader('Content-Type', 'application/json');
  } on ChilkatException {
    print('Could not prepare the request.');
    return;
  }

  try {
    rest.addHeader('Accept', 'application/json;odata=minimalmetadata');
  } on ChilkatException {
    print('Could not prepare the request.');
    return;
  }

  final partitionKey = 'customers-west';
  final rowKey = 'customer-001';
  final encodedPk = CkStringBuilder();
  try {
    encodedPk.append(partitionKey);
  } on ChilkatException {
    print('Could not prepare the request.');
    return;
  }

  final escapedencodedPk = encodedPk.replace('\'', '\'\'');
  try {
    encodedPk.encode('url_rfc3986', 'utf-8');
  } on ChilkatException {
    print('Could not prepare the request.');
    return;
  }

  final encodedRk = CkStringBuilder();
  try {
    encodedRk.append(rowKey);
  } on ChilkatException {
    print('Could not prepare the request.');
    return;
  }

  final escapedencodedRk = encodedRk.replace('\'', '\'\'');
  try {
    encodedRk.encode('url_rfc3986', 'utf-8');
  } on ChilkatException {
    print('Could not prepare the request.');
    return;
  }

  // Escape apostrophes for OData first, then percent-encode each key once.
  final entityPath = CkStringBuilder();
  try {
    entityPath.append('/ExampleCustomers(PartitionKey=\'');
  } on ChilkatException {
    print('Could not prepare the request.');
    return;
  }

  try {
    entityPath.append(encodedPk.getAsString());
  } on ChilkatException {
    print('Could not prepare the request.');
    return;
  }

  try {
    entityPath.append('\',RowKey=\'');
  } on ChilkatException {
    print('Could not prepare the request.');
    return;
  }

  try {
    entityPath.append(encodedRk.getAsString());
  } on ChilkatException {
    print('Could not prepare the request.');
    return;
  }

  try {
    entityPath.append('\')');
  } on ChilkatException {
    print('Could not prepare the request.');
    return;
  }

  resourcePath = entityPath.getAsString();
  var attempt = 0;
  var baseDelayMs = 1000;
  var finished = false;
  final timer = CkHttp();
  final jitter = CkPrng();
  final retryText = CkStringBuilder();
  final digits = CkStringBuilder();
  try {
    digits.append('0123456789');
  } on ChilkatException {
    print('Could not prepare the request.');
    return;
  }

  final retryDate = CkDateTime();
  final currentTime = CkDateTime();
  while (!finished) {
    attempt++;
    try {
      responseText = rest.fullRequestNoBody('GET', resourcePath);
    } on ChilkatException {
      print('Transport failure; this example does not retry incomplete reads.');
      return;
    }

    final httpStatus = rest.responseStatusCode;
    if (httpStatus == 200) {
      finished = true;
    } else {
      if ((httpStatus != 408) && ((httpStatus != 429) && ((httpStatus != 500) && ((httpStatus != 502) && ((httpStatus != 503) && (httpStatus != 504)))))) {
        print('Non-retryable HTTP status; inspect request ID privately.');
        return;
      }

      if (attempt >= 5) {
        print('Retry limit reached.');
        return;
      }

      var delayMs = baseDelayMs + jitter.randomInt(0, 250);
      if (!jitter.lastMethodSuccess) {
        print('Could not generate retry jitter.');
        return;
      }

      try {
        retryText.setString(rest.responseHdrByName('Retry-After'));
      } on ChilkatException {
        print('Could not prepare the request.');
        return;
      }

      try {
        retryText.trim();
      } on ChilkatException {
        print('Could not prepare the request.');
        return;
      }

      if (retryText.length > 0) {
        var numericDelay = true;
        var digitIndex = 0;
        while (digitIndex < retryText.length) {
          if (!digits.contains(retryText.getRange(digitIndex, 1, false), true)) {
            numericDelay = false;
          }

          digitIndex++;
        }

        var requestedSeconds = 0;
        if (numericDelay) {
          if (retryText.length > 2) {
            print('Retry-After exceeds this example wait budget.');
            return;
          }

          requestedSeconds = retryText.intValue;
        } else {
          try {
            retryDate.setFromRfc822(retryText.getAsString());
          } on ChilkatException {
            print('Invalid Retry-After date.');
            return;
          }

          try {
            currentTime.setFromCurrentSystemTime();
          } on ChilkatException {
            print('Could not prepare the request.');
            return;
          }

          requestedSeconds = retryDate.diffSeconds(currentTime) + 1;
        }

        if (requestedSeconds > 30) {
          print('Server requested a longer wait; stop instead of retrying too soon.');
          return;
        }

        if (requestedSeconds < 0) {
          requestedSeconds = 0;
        }

        if (requestedSeconds * 1000 > delayMs) {
          delayMs = requestedSeconds * 1000;
        }
      }

      // Retry only this GET; never copy this loop blindly to mutation requests.
      timer.sleepMs(delayMs);
      baseDelayMs = baseDelayMs * 2;
      rest.disconnect(10);
      try {
        connection.connect(endpoint.getAsString(), 443, true, 20000);
      } on ChilkatException {
        print('TLS reconnection failed.');
        return;
      }

      try {
        rest.useConnection(connection, false);
      } on ChilkatException {
        print('Could not prepare the request.');
        return;
      }
    }
  }

  try {
    result.load(responseText);
  } on ChilkatException {
    print('Expected well-formed JSON.');
    return;
  }

  textCompare.clear();
  textCompare.setString(result.stringOf('PartitionKey'));
  final sameText3 = textCompare.contentsEqual('', true);
  if ((result.jsonTypeOf('PartitionKey') != 1) || (sameText3)) {
    print('Missing string PartitionKey.');
    return;
  }

  textCompare.clear();
  textCompare.setString(result.stringOf('RowKey'));
  final sameText4 = textCompare.contentsEqual('', true);
  if ((result.jsonTypeOf('RowKey') != 1) || (sameText4)) {
    print('Missing string RowKey.');
    return;
  }

  textCompare.clear();
  textCompare.setString(result.stringOf('PartitionKey'));
  final sameText5 = textCompare.contentsEqual(partitionKey, true);
  textCompare.clear();
  textCompare.setString(result.stringOf('RowKey'));
  final sameText6 = textCompare.contentsEqual(rowKey, true);
  if ((!sameText5) || (!sameText6)) {
    print('Returned entity keys do not match.');
    return;
  }

  print('Entity read completed with bounded retries.');
}