Share this page

# LrSqsClient.addMessageToBatch

Adds a message to a container that stores messages to be sent.

`public static void addMessageToBatch(String messageBody)`

`public static void addMessageToBatch(String messageBody, String messageGroupId)`

`public static void addMessageToBatch(String messageBody, String messageGroupId, String deduplicationId)`

## Arguments

Name | Description
--- | ---
messageBody | The message body to be sent.
messageGroupId | The message group to which the message belongs.
messageDeduplicationId | The deduplication ID of the message.

## Return values

This function does not return any values.

## General information

This function adds a message to a container that stores messages to be sent using the SendMessageBatchRequest API. The message is not sent directly but stored in a container in order to be sent along with other messages as a batch.

If the message group ID and deduplication ID arguments are used, the queue must be of the type FIFO (first in first out). Otherwise, the message queue must be standard.

## Example

Copy code

    public void sendMessageByBatch_FIFO(){
     LrSqsClient.initClient(region, fifoQueueUrl);
            LrSqsClient.initMessageBatch();
            LrSqsClient.addMessageToBatch("batch message 0", "group1", "dup1");
            LrSqsClient.addMessageToBatch("batch message 1", "group1", "dup2");

            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 3", "group1", "dup3", "idInBatch1", messageAttributes);

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

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

            LrSqsClient.closeClient();
    }

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