Share this page

# LrSqsClient.addMessageToBatchEx

Adds a message with multiple attributes to a container that stores messages to be sent.

`public static void addMessageToBatchEx(String messageBody, Integer delaySeconds, String messageIdWithinBatch, Map<String, LrSqsMessageAttributeValue> messageAttributes)`

`public static void addMessageToBatchEx(String messageBody, String messageGroupId, String deduplicationId, String messageIdWithinBatch, Map<String, LrSqsMessageAttributeValue> messageAttributes)`

## 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.
delaySeconds | The delay (in seconds) between when the message is sent and when the message appears in the queue.
messageIdWithinBatch | The message ID within the current batch.
messageAttributes | User-defined attributes for the message to be sent, specified as key-value pairs.

## 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. It allows the message to be constructed with user-defined attributes. 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 25.1-25.3 Function Reference 25.1-25.3 All View Local Help Center View Online Help Center Version: