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

NameDescription
messageBodyThe message body to be sent.
messageGroupIdThe message group to which the message belongs.
messageDeduplicationIdThe deduplication ID of the message.
delaySecondsThe delay (in seconds) between when the message is sent and when the message appears in the queue.
messageIdWithinBatchThe message ID within the current batch.
messageAttributesUser-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> succesfull_res = batchResponse.successful();
                
        for (LrSqsSendMessageBatchStatusEntry entry : succesfull_res){
            lr.output_message("Message sent successfully: " + entry.messageId());
        }
        
        LrSqsClient.closeClient();
}