Amazon SQS: Send a Batch and Handle Partial Failures
See more Amazon SQS Examples
Send two standard-queue messages in one request, using short request-local IDs m0 and m1 to correlate results. A batch supports 1–10 entries and a total payload of at most 1 MiB. This example counts UTF-8 body bytes and verifies every successful body MD5. It sends no custom attributes; add their sizes to the accounting if you extend it.
HTTP 200 may include both Successful and Failed arrays. A Hashtable detects unknown, duplicate or missing result IDs. Report failures by Id, Code and SenderFault; retry only appropriate failed entries with bounded backoff. Do not repeat successful sends after a partial result. A lost response leaves the outcome uncertain, and standard queues do not deduplicate retries automatically. Batch request Id is distinct from SQS MessageId.
Uses SQS's AWS JSON protocol: POST to the regional root / with Content-Type: application/x-amz-json-1.0 and an operation-specific X-Amz-Target: AmazonSQS.... Chilkat.Rest and AuthAws sign with AWS Signature Version 4, service sqs. AWS still supports the older Query/XML protocol; these examples use JSON for simpler request and response handling. No AWS SDK is required.
Provide current IAM credentials in a private qa_data/aws/sqs.json with string fields access_key, secret_key, and session_token for temporary credentials. Queue-specific examples also read queue_url from this file. Set the region in the code to match the queue. These examples use commercial regional endpoints; other partitions or custom endpoints require corresponding changes. Prefer short-lived role credentials. The file is explicitly loaded; profiles and credential refresh are not automatic. Keep it outside public content and source control. The temporary token is included in the signed query; keep URLs and diagnostics private. TLS certificate verification is enabled.
Transport completion, HTTP status, and response validity are checked separately. Use bounded backoff with jitter for retryable errors, and refresh expired credentials. A timed-out write or receive may already have been accepted. Standard queues can deliver duplicates: make application processing idempotent and delete only after successful processing. Automatic reconnection is disabled for writes and receives to avoid replay after a lost response. Read-only queue listing permits reconnection.
Required IAM action: sqs:SendMessage (also authorizes SendMessageBatch). Scope access to the intended queue. Customer-managed KMS encryption can require additional KMS permissions for producers and consumers.
AWS SendMessageBatch reference
Chilkat Visual FoxPro Downloads
LOCAL lnSuccess
LOCAL loTextCompare
LOCAL loCredentials
LOCAL lnSameText1
LOCAL lnSameText2
LOCAL lcRegion
LOCAL loEndpoint
LOCAL lcQueueUrl
LOCAL lnSameText3
LOCAL loExpectedPrefix
LOCAL loQueueText
LOCAL loAws
LOCAL loRest
LOCAL lnSameText4
LOCAL loConnection
LOCAL loBody
LOCAL loResult
LOCAL loRequestBody
LOCAL loResponseBody
LOCAL lnNumEntries
LOCAL loExpected
LOCAL loBodyBytes
LOCAL loReturnedMd5
LOCAL lnTotalBytes
LOCAL i
LOCAL lcEntryId
LOCAL lcMd5
LOCAL loSeenResults
LOCAL lnResultCount
LOCAL lnFailedCount
LOCAL lnSuccessfulType
LOCAL lnSuccessfulIndex
LOCAL lnSameText5
LOCAL lcSuccessfulId
LOCAL lnSameText6
LOCAL lnSameText7
LOCAL lcExpectedMd5
LOCAL lnFailedType
LOCAL lnFailedIndex
LOCAL lnSameText8
LOCAL lcFailedId
LOCAL lnSameText9
lnSuccess = 0
* StringBuilder compares text by value in every generated language.
loTextCompare = CreateObject('Chilkat.StringBuilder')
* Assumes Chilkat is unlocked. See Global Unlock Sample.
lnSuccess = 0
* Private configuration, not a file in public web content or source control.
* Load current IAM credentials authorized for the SQS operation.
loCredentials = CreateObject('Chilkat.JsonObject')
loCredentials.Strict = 1
lnSuccess = loCredentials.LoadFile("qa_data/aws/sqs.json")
IF (lnSuccess <> 1) THEN
? "Could not load private AWS credentials."
RELEASE loTextCompare
RELEASE loCredentials
CANCEL
ENDIF
loTextCompare.Clear()
loTextCompare.SetString(loCredentials.StringOf("access_key"))
lnSameText1 = loTextCompare.ContentsEqual("",1)
IF ((loCredentials.JsonTypeOf("access_key") <> 1) OR (lnSameText1 = 1)) THEN
? "Missing or invalid access_key."
RELEASE loTextCompare
RELEASE loCredentials
CANCEL
ENDIF
loTextCompare.Clear()
loTextCompare.SetString(loCredentials.StringOf("secret_key"))
lnSameText2 = loTextCompare.ContentsEqual("",1)
IF ((loCredentials.JsonTypeOf("secret_key") <> 1) OR (lnSameText2 = 1)) THEN
? "Missing or invalid secret_key."
RELEASE loTextCompare
RELEASE loCredentials
CANCEL
ENDIF
* Set this once to the region containing the queue.
lcRegion = "us-west-2"
loEndpoint = CreateObject('Chilkat.StringBuilder')
lnSuccess = loEndpoint.Append("sqs.")
IF (lnSuccess <> 1) THEN
? "Could not prepare the request."
RELEASE loTextCompare
RELEASE loCredentials
RELEASE loEndpoint
CANCEL
ENDIF
lnSuccess = loEndpoint.Append(lcRegion)
IF (lnSuccess <> 1) THEN
? "Could not prepare the request."
RELEASE loTextCompare
RELEASE loCredentials
RELEASE loEndpoint
CANCEL
ENDIF
lnSuccess = loEndpoint.Append(".amazonaws.com")
IF (lnSuccess <> 1) THEN
? "Could not prepare the request."
RELEASE loTextCompare
RELEASE loCredentials
RELEASE loEndpoint
CANCEL
ENDIF
* Use the exact QueueUrl returned by CreateQueue, GetQueueUrl, or ListQueues.
* This example targets a standard commercial regional endpoint, not a custom endpoint.
lcQueueUrl = loCredentials.StringOf("queue_url")
loTextCompare.Clear()
loTextCompare.SetString(lcQueueUrl)
lnSameText3 = loTextCompare.ContentsEqual("",1)
IF ((loCredentials.JsonTypeOf("queue_url") <> 1) OR (lnSameText3 = 1)) THEN
? "Missing or invalid queue_url in sqs.json."
RELEASE loTextCompare
RELEASE loCredentials
RELEASE loEndpoint
CANCEL
ENDIF
loExpectedPrefix = CreateObject('Chilkat.StringBuilder')
lnSuccess = loExpectedPrefix.Append("https://")
IF (lnSuccess <> 1) THEN
? "Could not prepare the request."
RELEASE loTextCompare
RELEASE loCredentials
RELEASE loEndpoint
RELEASE loExpectedPrefix
CANCEL
ENDIF
lnSuccess = loExpectedPrefix.Append(loEndpoint.GetAsString())
IF (lnSuccess <> 1) THEN
? "Could not prepare the request."
RELEASE loTextCompare
RELEASE loCredentials
RELEASE loEndpoint
RELEASE loExpectedPrefix
CANCEL
ENDIF
lnSuccess = loExpectedPrefix.Append("/")
IF (lnSuccess <> 1) THEN
? "Could not prepare the request."
RELEASE loTextCompare
RELEASE loCredentials
RELEASE loEndpoint
RELEASE loExpectedPrefix
CANCEL
ENDIF
loQueueText = CreateObject('Chilkat.StringBuilder')
lnSuccess = loQueueText.Append(lcQueueUrl)
IF (lnSuccess <> 1) THEN
? "Could not prepare the request."
RELEASE loTextCompare
RELEASE loCredentials
RELEASE loEndpoint
RELEASE loExpectedPrefix
RELEASE loQueueText
CANCEL
ENDIF
IF (loQueueText.StartsWith(loExpectedPrefix.GetAsString(),1) <> 1) THEN
? "Queue URL must use HTTPS and the configured SQS region."
RELEASE loTextCompare
RELEASE loCredentials
RELEASE loEndpoint
RELEASE loExpectedPrefix
RELEASE loQueueText
CANCEL
ENDIF
loAws = CreateObject('Chilkat.AuthAws')
loAws.AccessKey = loCredentials.StringOf("access_key")
loAws.SecretKey = loCredentials.StringOf("secret_key")
loAws.Region = lcRegion
loAws.ServiceName = "sqs"
loAws.SignatureVersion = 4
loRest = CreateObject('Chilkat.Rest')
loRest.ConnectTimeoutMs = 20000
loRest.IdleTimeoutMs = 60000
lnSuccess = loRest.SetAuthAws(loAws)
IF (lnSuccess <> 1) THEN
? "Could not configure AWS signing."
RELEASE loTextCompare
RELEASE loCredentials
RELEASE loEndpoint
RELEASE loExpectedPrefix
RELEASE loQueueText
RELEASE loAws
RELEASE loRest
CANCEL
ENDIF
* Temporary IAM/STS credentials require their session token on every signed request.
* AddQueryParam includes it in SigV4's canonical query. Never log the request URL.
* Leave session_token absent or empty only for credentials that do not have one.
IF (loCredentials.HasMember("session_token") = 1) THEN
IF (loCredentials.JsonTypeOf("session_token") <> 1) THEN
? "session_token must be a string."
RELEASE loTextCompare
RELEASE loCredentials
RELEASE loEndpoint
RELEASE loExpectedPrefix
RELEASE loQueueText
RELEASE loAws
RELEASE loRest
CANCEL
ENDIF
loTextCompare.Clear()
loTextCompare.SetString(loCredentials.StringOf("session_token"))
lnSameText4 = loTextCompare.ContentsEqual("",1)
IF (lnSameText4 <> 1) THEN
lnSuccess = loRest.AddQueryParam("X-Amz-Security-Token",loCredentials.StringOf("session_token"))
IF (lnSuccess <> 1) THEN
? "Could not set the session-token parameter."
RELEASE loTextCompare
RELEASE loCredentials
RELEASE loEndpoint
RELEASE loExpectedPrefix
RELEASE loQueueText
RELEASE loAws
RELEASE loRest
CANCEL
ENDIF
ENDIF
ENDIF
* Supply a Socket to explicitly enable TLS certificate verification.
loConnection = CreateObject('Chilkat.Socket')
loConnection.RequireSslCertVerify = 1
loConnection.MaxReadIdleMs = 60000
loConnection.MaxSendIdleMs = 60000
lnSuccess = loConnection.Connect(loEndpoint.GetAsString(),443,1,20000)
IF (lnSuccess <> 1) THEN
? "TLS connection failed; inspect diagnostics privately."
RELEASE loTextCompare
RELEASE loCredentials
RELEASE loEndpoint
RELEASE loExpectedPrefix
RELEASE loQueueText
RELEASE loAws
RELEASE loRest
RELEASE loConnection
CANCEL
ENDIF
* Do not automatically reconnect/replay a write or receive after a lost response.
lnSuccess = loRest.UseConnection(loConnection,0)
IF (lnSuccess <> 1) THEN
? "Could not attach the TLS connection."
RELEASE loTextCompare
RELEASE loCredentials
RELEASE loEndpoint
RELEASE loExpectedPrefix
RELEASE loQueueText
RELEASE loAws
RELEASE loRest
RELEASE loConnection
CANCEL
ENDIF
lnSuccess = loRest.AddHeader("Content-Type","application/x-amz-json-1.0")
IF (lnSuccess <> 1) THEN
? "Could not set the content type."
RELEASE loTextCompare
RELEASE loCredentials
RELEASE loEndpoint
RELEASE loExpectedPrefix
RELEASE loQueueText
RELEASE loAws
RELEASE loRest
RELEASE loConnection
CANCEL
ENDIF
loBody = CreateObject('Chilkat.JsonObject')
loResult = CreateObject('Chilkat.JsonObject')
loResult.Strict = 1
loRequestBody = CreateObject('Chilkat.StringBuilder')
loResponseBody = CreateObject('Chilkat.StringBuilder')
lnSuccess = loRest.AddHeader("X-Amz-Target","AmazonSQS.SendMessageBatch")
IF (lnSuccess <> 1) THEN
? "Could not prepare the request."
RELEASE loTextCompare
RELEASE loCredentials
RELEASE loEndpoint
RELEASE loExpectedPrefix
RELEASE loQueueText
RELEASE loAws
RELEASE loRest
RELEASE loConnection
RELEASE loBody
RELEASE loResult
RELEASE loRequestBody
RELEASE loResponseBody
CANCEL
ENDIF
lnSuccess = loBody.UpdateString("QueueUrl",lcQueueUrl)
IF (lnSuccess <> 1) THEN
? "Could not prepare the request."
RELEASE loTextCompare
RELEASE loCredentials
RELEASE loEndpoint
RELEASE loExpectedPrefix
RELEASE loQueueText
RELEASE loAws
RELEASE loRest
RELEASE loConnection
RELEASE loBody
RELEASE loResult
RELEASE loRequestBody
RELEASE loResponseBody
CANCEL
ENDIF
* Standard queue; fixed small bodies keep this example easy to adapt.
lnSuccess = loBody.UpdateString("Entries[0].Id","m0")
IF (lnSuccess <> 1) THEN
? "Could not prepare the request."
RELEASE loTextCompare
RELEASE loCredentials
RELEASE loEndpoint
RELEASE loExpectedPrefix
RELEASE loQueueText
RELEASE loAws
RELEASE loRest
RELEASE loConnection
RELEASE loBody
RELEASE loResult
RELEASE loRequestBody
RELEASE loResponseBody
CANCEL
ENDIF
lnSuccess = loBody.UpdateString("Entries[0].MessageBody","First example message.")
IF (lnSuccess <> 1) THEN
? "Could not prepare the request."
RELEASE loTextCompare
RELEASE loCredentials
RELEASE loEndpoint
RELEASE loExpectedPrefix
RELEASE loQueueText
RELEASE loAws
RELEASE loRest
RELEASE loConnection
RELEASE loBody
RELEASE loResult
RELEASE loRequestBody
RELEASE loResponseBody
CANCEL
ENDIF
lnSuccess = loBody.UpdateString("Entries[1].Id","m1")
IF (lnSuccess <> 1) THEN
? "Could not prepare the request."
RELEASE loTextCompare
RELEASE loCredentials
RELEASE loEndpoint
RELEASE loExpectedPrefix
RELEASE loQueueText
RELEASE loAws
RELEASE loRest
RELEASE loConnection
RELEASE loBody
RELEASE loResult
RELEASE loRequestBody
RELEASE loResponseBody
CANCEL
ENDIF
lnSuccess = loBody.UpdateString("Entries[1].MessageBody","Second example message.")
IF (lnSuccess <> 1) THEN
? "Could not prepare the request."
RELEASE loTextCompare
RELEASE loCredentials
RELEASE loEndpoint
RELEASE loExpectedPrefix
RELEASE loQueueText
RELEASE loAws
RELEASE loRest
RELEASE loConnection
RELEASE loBody
RELEASE loResult
RELEASE loRequestBody
RELEASE loResponseBody
CANCEL
ENDIF
lnNumEntries = loBody.SizeOfArray("Entries")
IF ((lnNumEntries < 1) OR (lnNumEntries > 10)) THEN
? "A batch must have 1 through 10 entries."
RELEASE loTextCompare
RELEASE loCredentials
RELEASE loEndpoint
RELEASE loExpectedPrefix
RELEASE loQueueText
RELEASE loAws
RELEASE loRest
RELEASE loConnection
RELEASE loBody
RELEASE loResult
RELEASE loRequestBody
RELEASE loResponseBody
CANCEL
ENDIF
loExpected = CreateObject('Chilkat.Hashtable')
loBodyBytes = CreateObject('Chilkat.BinData')
loReturnedMd5 = CreateObject('Chilkat.StringBuilder')
lnTotalBytes = 0
i = 0
DO WHILE (i < lnNumEntries)
loBody.I = i
lcEntryId = loBody.StringOf("Entries[i].Id")
IF (loExpected.Contains(lcEntryId) = 1) THEN
? "Batch entry IDs must be unique."
RELEASE loTextCompare
RELEASE loCredentials
RELEASE loEndpoint
RELEASE loExpectedPrefix
RELEASE loQueueText
RELEASE loAws
RELEASE loRest
RELEASE loConnection
RELEASE loBody
RELEASE loResult
RELEASE loRequestBody
RELEASE loResponseBody
RELEASE loExpected
RELEASE loBodyBytes
RELEASE loReturnedMd5
CANCEL
ENDIF
lnSuccess = loBodyBytes.Clear()
IF (lnSuccess <> 1) THEN
? "Could not prepare the request."
RELEASE loTextCompare
RELEASE loCredentials
RELEASE loEndpoint
RELEASE loExpectedPrefix
RELEASE loQueueText
RELEASE loAws
RELEASE loRest
RELEASE loConnection
RELEASE loBody
RELEASE loResult
RELEASE loRequestBody
RELEASE loResponseBody
RELEASE loExpected
RELEASE loBodyBytes
RELEASE loReturnedMd5
CANCEL
ENDIF
lnSuccess = loBodyBytes.AppendString(loBody.StringOf("Entries[i].MessageBody"),"utf-8")
IF (lnSuccess <> 1) THEN
? "Could not prepare the request."
RELEASE loTextCompare
RELEASE loCredentials
RELEASE loEndpoint
RELEASE loExpectedPrefix
RELEASE loQueueText
RELEASE loAws
RELEASE loRest
RELEASE loConnection
RELEASE loBody
RELEASE loResult
RELEASE loRequestBody
RELEASE loResponseBody
RELEASE loExpected
RELEASE loBodyBytes
RELEASE loReturnedMd5
CANCEL
ENDIF
IF ((loBodyBytes.NumBytes = 0) OR (loBodyBytes.NumBytes > 1048576)) THEN
? "Message body must be nonempty and at most 1 MiB."
RELEASE loTextCompare
RELEASE loCredentials
RELEASE loEndpoint
RELEASE loExpectedPrefix
RELEASE loQueueText
RELEASE loAws
RELEASE loRest
RELEASE loConnection
RELEASE loBody
RELEASE loResult
RELEASE loRequestBody
RELEASE loResponseBody
RELEASE loExpected
RELEASE loBodyBytes
RELEASE loReturnedMd5
CANCEL
ENDIF
lnTotalBytes = lnTotalBytes + loBodyBytes.NumBytes
IF (lnTotalBytes > 1048576) THEN
? "Total batch payload exceeds 1 MiB."
RELEASE loTextCompare
RELEASE loCredentials
RELEASE loEndpoint
RELEASE loExpectedPrefix
RELEASE loQueueText
RELEASE loAws
RELEASE loRest
RELEASE loConnection
RELEASE loBody
RELEASE loResult
RELEASE loRequestBody
RELEASE loResponseBody
RELEASE loExpected
RELEASE loBodyBytes
RELEASE loReturnedMd5
CANCEL
ENDIF
lcMd5 = loBodyBytes.GetHash("md5","hex")
IF (loBodyBytes.LastMethodSuccess <> 1) THEN
? "Could not hash body."
RELEASE loTextCompare
RELEASE loCredentials
RELEASE loEndpoint
RELEASE loExpectedPrefix
RELEASE loQueueText
RELEASE loAws
RELEASE loRest
RELEASE loConnection
RELEASE loBody
RELEASE loResult
RELEASE loRequestBody
RELEASE loResponseBody
RELEASE loExpected
RELEASE loBodyBytes
RELEASE loReturnedMd5
CANCEL
ENDIF
lnSuccess = loExpected.AddStr(lcEntryId,lcMd5)
IF (lnSuccess <> 1) THEN
? "Could not prepare the request."
RELEASE loTextCompare
RELEASE loCredentials
RELEASE loEndpoint
RELEASE loExpectedPrefix
RELEASE loQueueText
RELEASE loAws
RELEASE loRest
RELEASE loConnection
RELEASE loBody
RELEASE loResult
RELEASE loRequestBody
RELEASE loResponseBody
RELEASE loExpected
RELEASE loBodyBytes
RELEASE loReturnedMd5
CANCEL
ENDIF
i = i + 1
ENDDO
* EmitSb appends, so clear both builders before each request/page.
loRequestBody.Clear()
loResponseBody.Clear()
lnSuccess = loBody.EmitSb(loRequestBody)
IF (lnSuccess <> 1) THEN
? "Could not serialize JSON."
RELEASE loTextCompare
RELEASE loCredentials
RELEASE loEndpoint
RELEASE loExpectedPrefix
RELEASE loQueueText
RELEASE loAws
RELEASE loRest
RELEASE loConnection
RELEASE loBody
RELEASE loResult
RELEASE loRequestBody
RELEASE loResponseBody
RELEASE loExpected
RELEASE loBodyBytes
RELEASE loReturnedMd5
CANCEL
ENDIF
lnSuccess = loRest.FullRequestSb("POST","/",loRequestBody,loResponseBody)
IF (lnSuccess <> 1) THEN
? "Request did not complete; inspect diagnostics privately."
* A write or receive may have reached SQS. Do not blindly replay it.
RELEASE loTextCompare
RELEASE loCredentials
RELEASE loEndpoint
RELEASE loExpectedPrefix
RELEASE loQueueText
RELEASE loAws
RELEASE loRest
RELEASE loConnection
RELEASE loBody
RELEASE loResult
RELEASE loRequestBody
RELEASE loResponseBody
RELEASE loExpected
RELEASE loBodyBytes
RELEASE loReturnedMd5
CANCEL
ENDIF
IF (loRest.ResponseStatusCode <> 200) THEN
? "SQS HTTP status: " + STR(loRest.ResponseStatusCode)
? "AWS request ID: " + loRest.ResponseHdrByName("x-amzn-RequestId")
lnSuccess = loResult.LoadSb(loResponseBody)
IF ((lnSuccess = 1) AND (loResult.JsonTypeOf("__type") = 1)) THEN
? "AWS error type: " + loResult.StringOf("__type")
ELSE
? "AWS error type: " + loRest.ResponseHdrByName("x-amzn-errortype")
ENDIF
* Error messages, payloads, receipt handles and signed URLs can be private.
* HTTP 400 can be throttling, expired credentials, or invalid parameters.
RELEASE loTextCompare
RELEASE loCredentials
RELEASE loEndpoint
RELEASE loExpectedPrefix
RELEASE loQueueText
RELEASE loAws
RELEASE loRest
RELEASE loConnection
RELEASE loBody
RELEASE loResult
RELEASE loRequestBody
RELEASE loResponseBody
RELEASE loExpected
RELEASE loBodyBytes
RELEASE loReturnedMd5
CANCEL
ENDIF
lnSuccess = loResponseBody.Trim()
IF (lnSuccess <> 1) THEN
? "Could not inspect response."
RELEASE loTextCompare
RELEASE loCredentials
RELEASE loEndpoint
RELEASE loExpectedPrefix
RELEASE loQueueText
RELEASE loAws
RELEASE loRest
RELEASE loConnection
RELEASE loBody
RELEASE loResult
RELEASE loRequestBody
RELEASE loResponseBody
RELEASE loExpected
RELEASE loBodyBytes
RELEASE loReturnedMd5
CANCEL
ENDIF
IF (loResponseBody.StartsWith("{",1) <> 1) THEN
? "Expected a JSON object response."
RELEASE loTextCompare
RELEASE loCredentials
RELEASE loEndpoint
RELEASE loExpectedPrefix
RELEASE loQueueText
RELEASE loAws
RELEASE loRest
RELEASE loConnection
RELEASE loBody
RELEASE loResult
RELEASE loRequestBody
RELEASE loResponseBody
RELEASE loExpected
RELEASE loBodyBytes
RELEASE loReturnedMd5
CANCEL
ENDIF
lnSuccess = loResult.LoadSb(loResponseBody)
IF (lnSuccess <> 1) THEN
? "Expected well-formed JSON."
RELEASE loTextCompare
RELEASE loCredentials
RELEASE loEndpoint
RELEASE loExpectedPrefix
RELEASE loQueueText
RELEASE loAws
RELEASE loRest
RELEASE loConnection
RELEASE loBody
RELEASE loResult
RELEASE loRequestBody
RELEASE loResponseBody
RELEASE loExpected
RELEASE loBodyBytes
RELEASE loReturnedMd5
CANCEL
ENDIF
loSeenResults = CreateObject('Chilkat.Hashtable')
lnResultCount = 0
lnFailedCount = 0
lnSuccessfulType = loResult.JsonTypeOf("Successful")
IF ((lnSuccessfulType <> -1) AND (lnSuccessfulType <> 6)) THEN
IF (lnSuccessfulType <> 4) THEN
? "Expected Successful array."
RELEASE loTextCompare
RELEASE loCredentials
RELEASE loEndpoint
RELEASE loExpectedPrefix
RELEASE loQueueText
RELEASE loAws
RELEASE loRest
RELEASE loConnection
RELEASE loBody
RELEASE loResult
RELEASE loRequestBody
RELEASE loResponseBody
RELEASE loExpected
RELEASE loBodyBytes
RELEASE loReturnedMd5
RELEASE loSeenResults
CANCEL
ENDIF
lnSuccessfulIndex = 0
DO WHILE (lnSuccessfulIndex < loResult.SizeOfArray("Successful"))
loResult.I = lnSuccessfulIndex
loTextCompare.Clear()
loTextCompare.SetString(loResult.StringOf("Successful[i].Id"))
lnSameText5 = loTextCompare.ContentsEqual("",1)
IF ((loResult.JsonTypeOf("Successful[i].Id") <> 1) OR (lnSameText5 = 1)) THEN
? "Missing or invalid Successful[i].Id."
RELEASE loTextCompare
RELEASE loCredentials
RELEASE loEndpoint
RELEASE loExpectedPrefix
RELEASE loQueueText
RELEASE loAws
RELEASE loRest
RELEASE loConnection
RELEASE loBody
RELEASE loResult
RELEASE loRequestBody
RELEASE loResponseBody
RELEASE loExpected
RELEASE loBodyBytes
RELEASE loReturnedMd5
RELEASE loSeenResults
CANCEL
ENDIF
lcSuccessfulId = loResult.StringOf("Successful[i].Id")
IF (loExpected.Contains(lcSuccessfulId) <> 1) THEN
? "Unexpected batch result ID; outcome needs reconciliation."
RELEASE loTextCompare
RELEASE loCredentials
RELEASE loEndpoint
RELEASE loExpectedPrefix
RELEASE loQueueText
RELEASE loAws
RELEASE loRest
RELEASE loConnection
RELEASE loBody
RELEASE loResult
RELEASE loRequestBody
RELEASE loResponseBody
RELEASE loExpected
RELEASE loBodyBytes
RELEASE loReturnedMd5
RELEASE loSeenResults
CANCEL
ENDIF
IF (loSeenResults.Contains(lcSuccessfulId) = 1) THEN
? "Duplicate batch result ID; outcome needs reconciliation."
RELEASE loTextCompare
RELEASE loCredentials
RELEASE loEndpoint
RELEASE loExpectedPrefix
RELEASE loQueueText
RELEASE loAws
RELEASE loRest
RELEASE loConnection
RELEASE loBody
RELEASE loResult
RELEASE loRequestBody
RELEASE loResponseBody
RELEASE loExpected
RELEASE loBodyBytes
RELEASE loReturnedMd5
RELEASE loSeenResults
CANCEL
ENDIF
lnSuccess = loSeenResults.AddInt(lcSuccessfulId,1)
IF (lnSuccess <> 1) THEN
? "Could not prepare the request."
RELEASE loTextCompare
RELEASE loCredentials
RELEASE loEndpoint
RELEASE loExpectedPrefix
RELEASE loQueueText
RELEASE loAws
RELEASE loRest
RELEASE loConnection
RELEASE loBody
RELEASE loResult
RELEASE loRequestBody
RELEASE loResponseBody
RELEASE loExpected
RELEASE loBodyBytes
RELEASE loReturnedMd5
RELEASE loSeenResults
CANCEL
ENDIF
loTextCompare.Clear()
loTextCompare.SetString(loResult.StringOf("Successful[i].MessageId"))
lnSameText6 = loTextCompare.ContentsEqual("",1)
IF ((loResult.JsonTypeOf("Successful[i].MessageId") <> 1) OR (lnSameText6 = 1)) THEN
? "Missing or invalid Successful[i].MessageId."
RELEASE loTextCompare
RELEASE loCredentials
RELEASE loEndpoint
RELEASE loExpectedPrefix
RELEASE loQueueText
RELEASE loAws
RELEASE loRest
RELEASE loConnection
RELEASE loBody
RELEASE loResult
RELEASE loRequestBody
RELEASE loResponseBody
RELEASE loExpected
RELEASE loBodyBytes
RELEASE loReturnedMd5
RELEASE loSeenResults
CANCEL
ENDIF
loTextCompare.Clear()
loTextCompare.SetString(loResult.StringOf("Successful[i].MD5OfMessageBody"))
lnSameText7 = loTextCompare.ContentsEqual("",1)
IF ((loResult.JsonTypeOf("Successful[i].MD5OfMessageBody") <> 1) OR (lnSameText7 = 1)) THEN
? "Missing or invalid Successful[i].MD5OfMessageBody."
RELEASE loTextCompare
RELEASE loCredentials
RELEASE loEndpoint
RELEASE loExpectedPrefix
RELEASE loQueueText
RELEASE loAws
RELEASE loRest
RELEASE loConnection
RELEASE loBody
RELEASE loResult
RELEASE loRequestBody
RELEASE loResponseBody
RELEASE loExpected
RELEASE loBodyBytes
RELEASE loReturnedMd5
RELEASE loSeenResults
CANCEL
ENDIF
loReturnedMd5.Clear()
lnSuccess = loReturnedMd5.Append(loResult.StringOf("Successful[i].MD5OfMessageBody"))
IF (lnSuccess <> 1) THEN
? "Could not prepare the request."
RELEASE loTextCompare
RELEASE loCredentials
RELEASE loEndpoint
RELEASE loExpectedPrefix
RELEASE loQueueText
RELEASE loAws
RELEASE loRest
RELEASE loConnection
RELEASE loBody
RELEASE loResult
RELEASE loRequestBody
RELEASE loResponseBody
RELEASE loExpected
RELEASE loBodyBytes
RELEASE loReturnedMd5
RELEASE loSeenResults
CANCEL
ENDIF
lcExpectedMd5 = loExpected.LookupStr(lcSuccessfulId)
IF (loReturnedMd5.ContentsEqual(lcExpectedMd5,0) <> 1) THEN
? "Batch body MD5 mismatch; do not blindly resend."
RELEASE loTextCompare
RELEASE loCredentials
RELEASE loEndpoint
RELEASE loExpectedPrefix
RELEASE loQueueText
RELEASE loAws
RELEASE loRest
RELEASE loConnection
RELEASE loBody
RELEASE loResult
RELEASE loRequestBody
RELEASE loResponseBody
RELEASE loExpected
RELEASE loBodyBytes
RELEASE loReturnedMd5
RELEASE loSeenResults
CANCEL
ENDIF
? "Accepted entry: " + lcSuccessfulId + " Message ID: " + loResult.StringOf("Successful[i].MessageId")
lnResultCount = lnResultCount + 1
lnSuccessfulIndex = lnSuccessfulIndex + 1
ENDDO
ENDIF
lnFailedType = loResult.JsonTypeOf("Failed")
IF ((lnFailedType <> -1) AND (lnFailedType <> 6)) THEN
IF (lnFailedType <> 4) THEN
? "Expected Failed array."
RELEASE loTextCompare
RELEASE loCredentials
RELEASE loEndpoint
RELEASE loExpectedPrefix
RELEASE loQueueText
RELEASE loAws
RELEASE loRest
RELEASE loConnection
RELEASE loBody
RELEASE loResult
RELEASE loRequestBody
RELEASE loResponseBody
RELEASE loExpected
RELEASE loBodyBytes
RELEASE loReturnedMd5
RELEASE loSeenResults
CANCEL
ENDIF
lnFailedIndex = 0
DO WHILE (lnFailedIndex < loResult.SizeOfArray("Failed"))
loResult.I = lnFailedIndex
loTextCompare.Clear()
loTextCompare.SetString(loResult.StringOf("Failed[i].Id"))
lnSameText8 = loTextCompare.ContentsEqual("",1)
IF ((loResult.JsonTypeOf("Failed[i].Id") <> 1) OR (lnSameText8 = 1)) THEN
? "Missing or invalid Failed[i].Id."
RELEASE loTextCompare
RELEASE loCredentials
RELEASE loEndpoint
RELEASE loExpectedPrefix
RELEASE loQueueText
RELEASE loAws
RELEASE loRest
RELEASE loConnection
RELEASE loBody
RELEASE loResult
RELEASE loRequestBody
RELEASE loResponseBody
RELEASE loExpected
RELEASE loBodyBytes
RELEASE loReturnedMd5
RELEASE loSeenResults
CANCEL
ENDIF
lcFailedId = loResult.StringOf("Failed[i].Id")
IF (loExpected.Contains(lcFailedId) <> 1) THEN
? "Unexpected batch result ID; outcome needs reconciliation."
RELEASE loTextCompare
RELEASE loCredentials
RELEASE loEndpoint
RELEASE loExpectedPrefix
RELEASE loQueueText
RELEASE loAws
RELEASE loRest
RELEASE loConnection
RELEASE loBody
RELEASE loResult
RELEASE loRequestBody
RELEASE loResponseBody
RELEASE loExpected
RELEASE loBodyBytes
RELEASE loReturnedMd5
RELEASE loSeenResults
CANCEL
ENDIF
IF (loSeenResults.Contains(lcFailedId) = 1) THEN
? "Duplicate batch result ID; outcome needs reconciliation."
RELEASE loTextCompare
RELEASE loCredentials
RELEASE loEndpoint
RELEASE loExpectedPrefix
RELEASE loQueueText
RELEASE loAws
RELEASE loRest
RELEASE loConnection
RELEASE loBody
RELEASE loResult
RELEASE loRequestBody
RELEASE loResponseBody
RELEASE loExpected
RELEASE loBodyBytes
RELEASE loReturnedMd5
RELEASE loSeenResults
CANCEL
ENDIF
lnSuccess = loSeenResults.AddInt(lcFailedId,1)
IF (lnSuccess <> 1) THEN
? "Could not prepare the request."
RELEASE loTextCompare
RELEASE loCredentials
RELEASE loEndpoint
RELEASE loExpectedPrefix
RELEASE loQueueText
RELEASE loAws
RELEASE loRest
RELEASE loConnection
RELEASE loBody
RELEASE loResult
RELEASE loRequestBody
RELEASE loResponseBody
RELEASE loExpected
RELEASE loBodyBytes
RELEASE loReturnedMd5
RELEASE loSeenResults
CANCEL
ENDIF
loTextCompare.Clear()
loTextCompare.SetString(loResult.StringOf("Failed[i].Code"))
lnSameText9 = loTextCompare.ContentsEqual("",1)
IF ((loResult.JsonTypeOf("Failed[i].Code") <> 1) OR (lnSameText9 = 1)) THEN
? "Missing or invalid Failed[i].Code."
RELEASE loTextCompare
RELEASE loCredentials
RELEASE loEndpoint
RELEASE loExpectedPrefix
RELEASE loQueueText
RELEASE loAws
RELEASE loRest
RELEASE loConnection
RELEASE loBody
RELEASE loResult
RELEASE loRequestBody
RELEASE loResponseBody
RELEASE loExpected
RELEASE loBodyBytes
RELEASE loReturnedMd5
RELEASE loSeenResults
CANCEL
ENDIF
IF (loResult.JsonTypeOf("Failed[i].SenderFault") <> 5) THEN
? "Missing boolean SenderFault."
RELEASE loTextCompare
RELEASE loCredentials
RELEASE loEndpoint
RELEASE loExpectedPrefix
RELEASE loQueueText
RELEASE loAws
RELEASE loRest
RELEASE loConnection
RELEASE loBody
RELEASE loResult
RELEASE loRequestBody
RELEASE loResponseBody
RELEASE loExpected
RELEASE loBodyBytes
RELEASE loReturnedMd5
RELEASE loSeenResults
CANCEL
ENDIF
? "Failed entry: " + lcFailedId + " Code: " + loResult.StringOf("Failed[i].Code")
? "SenderFault: " + STR(loResult.BoolOf("Failed[i].SenderFault"))
* SenderFault=false is not a guarantee a retry will succeed. Inspect the error code.
lnFailedCount = lnFailedCount + 1
lnResultCount = lnResultCount + 1
lnFailedIndex = lnFailedIndex + 1
ENDDO
ENDIF
IF (lnResultCount <> lnNumEntries) THEN
? "Missing batch results; outcome needs reconciliation."
RELEASE loTextCompare
RELEASE loCredentials
RELEASE loEndpoint
RELEASE loExpectedPrefix
RELEASE loQueueText
RELEASE loAws
RELEASE loRest
RELEASE loConnection
RELEASE loBody
RELEASE loResult
RELEASE loRequestBody
RELEASE loResponseBody
RELEASE loExpected
RELEASE loBodyBytes
RELEASE loReturnedMd5
RELEASE loSeenResults
CANCEL
ENDIF
IF (lnFailedCount > 0) THEN
? "Batch contains failed entries. No automatic retries were made."
RELEASE loTextCompare
RELEASE loCredentials
RELEASE loEndpoint
RELEASE loExpectedPrefix
RELEASE loQueueText
RELEASE loAws
RELEASE loRest
RELEASE loConnection
RELEASE loBody
RELEASE loResult
RELEASE loRequestBody
RELEASE loResponseBody
RELEASE loExpected
RELEASE loBodyBytes
RELEASE loReturnedMd5
RELEASE loSeenResults
CANCEL
ENDIF
? "All batch entries accepted."
RELEASE loTextCompare
RELEASE loCredentials
RELEASE loEndpoint
RELEASE loExpectedPrefix
RELEASE loQueueText
RELEASE loAws
RELEASE loRest
RELEASE loConnection
RELEASE loBody
RELEASE loResult
RELEASE loRequestBody
RELEASE loResponseBody
RELEASE loExpected
RELEASE loBodyBytes
RELEASE loReturnedMd5
RELEASE loSeenResults