Share this page

# LrSqsClient.sendMessageBatch

Sends the batch of messages currently stored in the message container.

`public static LrSqsSendMessageBatchRequestStatus sendMessageBatch()`

## Return values

This function returns an LrSqsSendMessageBatchRequestStatus object. For details, see LrSqsSendMessageBatchRequestStatus.

## General information

This function sends all messages that are stored in the designated message container. If the container does not contain any messages, the function fails.

The batch can hold any number of messages. Upon calling the sendMessageBatch() function, the batch is split into smaller collections, of at most 10 messages each. Each such collection is sent as a separate request.

## Example

Copy code

    public void sendMessageByBatch_standard(){
            LrSqsClient.initClient(region, standardQueueUrl);
            LrSqsClient.initMessageBatch();
            LrSqsClient.addMessageToBatch("batch message 0");
            LrSqsClient.addMessageToBatch("batch message 1");

            LrSqsClient.initMessageBatch();
            LrSqsClient.addMessageToBatch("batch message 2");
            LrSqsClient.addMessageToBatch("batch message 3");

            LrSqsSendMessageBatchRequestStatus batchResponse = LrSqsClient.sendMessageBatch();
            Collection<LrSqsSendMessageBatchStatusEntry> successful_res = batchResponse.successful();

            if (successful_res.size() > 2)
                lr.error_message("batch size is not ok: " + successful_res.size());

            for (LrSqsSendMessageBatchStatusEntry entry : successful_res){
                lr.output_message("Message sent successfully: " + entry.messageId());
            }

            HashMap<String, LrSqsMessageAttributeValue> messageAttributes = new HashMap<String, LrSqsMessageAttributeValue>();
            messageAttributes.put("attr1", LrSqsClient.createMessageAttributeValueString("my string attribute value"));
            messageAttributes.put("attr2", LrSqsClient.createMessageAttributeValueInt("1234"));

            LrSqsClient.addMessageToBatchEx("batch message 4", null, null, messageAttributes);
            LrSqsClient.sendMessageBatch();

            LrSqsClient.closeClient();
    }

Tips to improve your search results... VuGen Function Reference Version 26.1 Function Reference 26.1 All View Local Help Center View Online Help Center Version: