-1

I am using SQS Batching using a Java client(AmazonSQSBufferedAsyncClient) for sending messages to SQS. I am sending 10 messages in one batch, But SQS monitoring is showing the "Number Of Messages Sent" is 10. Same for "Number Of Messages Received" and "Number Of Messages Deleted" Metric(Showing 10 count, expecting 1).

Below is the code to create a buffered client

final AmazonSQSAsync sqsAsync = new AmazonSQSAsyncClient(SQSConfig.getCreds());

final QueueBufferConfig config = new QueueBufferConfig()
        .withMaxBatchOpenMs(10000)
        .withMaxBatchSize(10)
        .withMaxInflightReceiveBatches(2)
        .withMaxDoneReceiveBatches(15);

config.setLongPoll(true);

bufferedSqs = new AmazonSQSBufferedAsyncClient(sqsAsync, config);

Below is the code to send a message.

public void sendBufferMessageInBatch(String message, String messageGroupId) throws ExecutionException, InterruptedException {

    SendMessageBatchRequest sqsBatchRequest = new SendMessageBatchRequest();

    sqsBatchRequest.setQueueUrl(SQSConfig.endpoint);
    List<SendMessageBatchRequestEntry> entryList = Stream.iterate(1, i -> i < 11, i -> i + 1)
            .map(numb -> {
                String sendMessage = message;
                sendMessage = sendMessage + "_" + numb;
                sendMessage = sendMessage + "_" + messageGroupId;
                SendMessageBatchRequestEntry entry = new SendMessageBatchRequestEntry();
                entry.setMessageBody(sendMessage);
                entry.setId("id_" + numb);
                printSendMessage(sendMessage);
                return entry;
            })
            .collect(Collectors.toList());

    sqsBatchRequest.setEntries(entryList);
    Future<SendMessageBatchResult> sendBatchMessageFuture = SQSConfig.bufferedSqs.sendMessageBatchAsync(sqsBatchRequest);
}

Questions:

  1. Why are "Number Of Messages Sent" metrics showing count 10 instead of count 1? (The batch message size is less than 64kb.)
  2. Whatever count shows on "Number Of Messages Sent" metric, that count is chargeable by aws?
  3. How can I track the API request that executes by SQS? How is SQS counting the API request while creating the bill?
luk2302
  • 55,258
  • 23
  • 97
  • 137
Akashsingla19
  • 690
  • 2
  • 8
  • 18

1 Answers1

1
  1. Because there were 10 messages being sent, that is what matters, not in how many batches they arrived in.

  2. No, it depends on how large the payload was / is, how many actual requests were needed to send those messages and how many requests were needed to receive and delete those messages. One request to send 10 message, one request to receive them all (will probably not work because you will not get 10 messages in a single Receive call with that few messages available), one request to delete them all => 3 requests. In practice that count will be higher since the Receive will probably only get 1 message meaning you need at least 10 such calls plus 10 delete calls.

  3. You generally can't. SQS (or some other internal tool) knows the request count to generate the bill but this information is not exposed.

luk2302
  • 55,258
  • 23
  • 97
  • 137