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.
Chilkat Java Downloads
import com.chilkatsoft.chilkat2.AuthAzureStorage;
import com.chilkatsoft.chilkat2.ChilkatException;
import com.chilkatsoft.chilkat2.DateTime;
import com.chilkatsoft.chilkat2.Http;
import com.chilkatsoft.chilkat2.JsonObject;
import com.chilkatsoft.chilkat2.Prng;
import com.chilkatsoft.chilkat2.Rest;
import com.chilkatsoft.chilkat2.Socket;
import com.chilkatsoft.chilkat2.StringBuilder;
public class ChilkatExample {
public static void main(String[] args) {
boolean success = false;
// StringBuilder compares text by value in every generated language.
StringBuilder textCompare = new StringBuilder();
// Assumes Chilkat is unlocked. See Global Unlock Sample.
success = false;
JsonObject config = new JsonObject();
config.setStrict(true);
try {
config.loadFile("qa_data/azure/storage.json");
} catch (ChilkatException e) {
System.out.println("Could not load private Azure configuration.");
return;
}
textCompare.clear();
textCompare.setString(config.stringOf("account"));
boolean sameText1 = textCompare.contentsEqual("", true);
if ((config.jsonTypeOf("account") != 1) || (sameText1)) {
System.out.println("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"));
boolean sameText2 = textCompare.contentsEqual("", true);
if ((config.jsonTypeOf("access_key") != 1) || (sameText2)) {
System.out.println("Supply the base64 account access key.");
return;
}
StringBuilder accountText = new StringBuilder();
try {
accountText.append(config.stringOf("account"));
} catch (ChilkatException e) {
System.out.println("Could not prepare the request.");
return;
}
if ((accountText.getLength() < 3) || (accountText.getLength() > 24)) {
System.out.println("Storage account names need 3-24 lowercase letters or digits.");
return;
}
StringBuilder allowedAccountChars = new StringBuilder();
try {
allowedAccountChars.append("abcdefghijklmnopqrstuvwxyz0123456789");
} catch (ChilkatException e) {
System.out.println("Could not prepare the request.");
return;
}
int charIndex = 0;
while (charIndex < accountText.getLength()) {
if (!allowedAccountChars.contains(accountText.getRange(charIndex, 1, false), true)) {
System.out.println("Storage account names need lowercase letters or digits.");
return;
}
charIndex = charIndex + 1;
}
StringBuilder endpoint = new StringBuilder();
try {
endpoint.append(config.stringOf("account"));
endpoint.append(".table.core.windows.net");
} catch (ChilkatException e) {
System.out.println("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.
String resourcePath = "/ExampleCustomers()";
Rest rest = new Rest();
rest.setConnectTimeoutMs(20000);
rest.setIdleTimeoutMs(60000);
AuthAzureStorage azAuth = new AuthAzureStorage();
azAuth.setAccount(config.stringOf("account"));
azAuth.setAccessKey(config.stringOf("access_key"));
azAuth.setService("Table");
azAuth.setScheme("SharedKey");
azAuth.setXMsVersion("2026-04-06");
try {
rest.setAuthAzureStorage(azAuth);
} catch (ChilkatException e) {
System.out.println("Could not configure Shared Key signing.");
return;
}
Socket connection = new Socket();
connection.setRequireSslCertVerify(true);
connection.setMaxReadIdleMs(60000);
connection.setMaxSendIdleMs(60000);
try {
connection.connect(endpoint.getAsString(), 443, true, 20000);
} catch (ChilkatException e) {
System.out.println("TLS connection failed; inspect diagnostics privately.");
return;
}
// Do not replay a write automatically after losing its response.
try {
rest.useConnection(connection, false);
} catch (ChilkatException e) {
System.out.println("Could not prepare the request.");
return;
}
String responseText = "";
JsonObject result = new JsonObject();
result.setStrict(true);
try {
rest.addHeader("DataServiceVersion", "3.0;NetFx");
rest.addHeader("MaxDataServiceVersion", "3.0;NetFx");
rest.addHeader("Content-Type", "application/json");
rest.addHeader("Accept", "application/json;odata=minimalmetadata");
} catch (ChilkatException e) {
System.out.println("Could not prepare the request.");
return;
}
String partitionKey = "customers-west";
String rowKey = "customer-001";
StringBuilder encodedPk = new StringBuilder();
try {
encodedPk.append(partitionKey);
} catch (ChilkatException e) {
System.out.println("Could not prepare the request.");
return;
}
int escapedencodedPk = encodedPk.replace("'", "''");
try {
encodedPk.encode("url_rfc3986", "utf-8");
} catch (ChilkatException e) {
System.out.println("Could not prepare the request.");
return;
}
StringBuilder encodedRk = new StringBuilder();
try {
encodedRk.append(rowKey);
} catch (ChilkatException e) {
System.out.println("Could not prepare the request.");
return;
}
int escapedencodedRk = encodedRk.replace("'", "''");
try {
encodedRk.encode("url_rfc3986", "utf-8");
} catch (ChilkatException e) {
System.out.println("Could not prepare the request.");
return;
}
// Escape apostrophes for OData first, then percent-encode each key once.
StringBuilder entityPath = new StringBuilder();
try {
entityPath.append("/ExampleCustomers(PartitionKey='");
entityPath.append(encodedPk.getAsString());
entityPath.append("',RowKey='");
entityPath.append(encodedRk.getAsString());
entityPath.append("')");
} catch (ChilkatException e) {
System.out.println("Could not prepare the request.");
return;
}
resourcePath = entityPath.getAsString();
int attempt = 0;
int baseDelayMs = 1000;
boolean finished = false;
Http timer = new Http();
Prng jitter = new Prng();
StringBuilder retryText = new StringBuilder();
StringBuilder digits = new StringBuilder();
try {
digits.append("0123456789");
} catch (ChilkatException e) {
System.out.println("Could not prepare the request.");
return;
}
DateTime retryDate = new DateTime();
DateTime currentTime = new DateTime();
while (!finished) {
attempt = attempt + 1;
try {
responseText = rest.fullRequestNoBody("GET", resourcePath);
} catch (ChilkatException e) {
System.out.println("Transport failure; this example does not retry incomplete reads.");
return;
}
int httpStatus = rest.getResponseStatusCode();
if (httpStatus == 200) {
finished = true;
} else {
if ((httpStatus != 408) && ((httpStatus != 429) && ((httpStatus != 500) && ((httpStatus != 502) && ((httpStatus != 503) && (httpStatus != 504)))))) {
System.out.println("Non-retryable HTTP status; inspect request ID privately.");
return;
}
if (attempt >= 5) {
System.out.println("Retry limit reached.");
return;
}
int delayMs = baseDelayMs + jitter.randomInt(0, 250);
if (!jitter.getLastMethodSuccess()) {
System.out.println("Could not generate retry jitter.");
return;
}
try {
retryText.setString(rest.responseHdrByName("Retry-After"));
retryText.trim();
} catch (ChilkatException e) {
System.out.println("Could not prepare the request.");
return;
}
if (retryText.getLength() > 0) {
boolean numericDelay = true;
int digitIndex = 0;
while (digitIndex < retryText.getLength()) {
if (!digits.contains(retryText.getRange(digitIndex, 1, false), true)) {
numericDelay = false;
}
digitIndex = digitIndex + 1;
}
int requestedSeconds = 0;
if (numericDelay) {
if (retryText.getLength() > 2) {
System.out.println("Retry-After exceeds this example wait budget.");
return;
}
requestedSeconds = retryText.getIntValue();
} else {
try {
retryDate.setFromRfc822(retryText.getAsString());
} catch (ChilkatException e) {
System.out.println("Invalid Retry-After date.");
return;
}
try {
currentTime.setFromCurrentSystemTime();
} catch (ChilkatException e) {
System.out.println("Could not prepare the request.");
return;
}
requestedSeconds = retryDate.diffSeconds(currentTime) + 1;
}
if (requestedSeconds > 30) {
System.out.println("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);
} catch (ChilkatException e) {
System.out.println("TLS reconnection failed.");
return;
}
try {
rest.useConnection(connection, false);
} catch (ChilkatException e) {
System.out.println("Could not prepare the request.");
return;
}
}
}
try {
result.load(responseText);
} catch (ChilkatException e) {
System.out.println("Expected well-formed JSON.");
return;
}
textCompare.clear();
textCompare.setString(result.stringOf("PartitionKey"));
boolean sameText3 = textCompare.contentsEqual("", true);
if ((result.jsonTypeOf("PartitionKey") != 1) || (sameText3)) {
System.out.println("Missing string PartitionKey.");
return;
}
textCompare.clear();
textCompare.setString(result.stringOf("RowKey"));
boolean sameText4 = textCompare.contentsEqual("", true);
if ((result.jsonTypeOf("RowKey") != 1) || (sameText4)) {
System.out.println("Missing string RowKey.");
return;
}
textCompare.clear();
textCompare.setString(result.stringOf("PartitionKey"));
boolean sameText5 = textCompare.contentsEqual(partitionKey, true);
textCompare.clear();
textCompare.setString(result.stringOf("RowKey"));
boolean sameText6 = textCompare.contentsEqual(rowKey, true);
if ((!sameText5) || (!sameText6)) {
System.out.println("Returned entity keys do not match.");
return;
}
System.out.println("Entity read completed with bounded retries.");
}
}