Initializes the container used to store messages to be sent.

public static void initMessageBatch()

Return values

This function does not return any values.

General information

This API initializes the container that stores messages to be sent using the SendMessageBatchRequest API. Cloud for AWS batch allows an arbitrary number of messages to be sent as a batch, and the result contains status details for each message sent.

After this function is called, the container is empty. Any messages left there will be deleted even if they were not previously sent.


Copy code
public void sendMessageByBatch_standard(){
        LrSqsClient.initClient(region, standardQueueUrl);
        LrSqsClient.addMessageToBatch("batch message 0");
        LrSqsClient.addMessageToBatch("batch message 1");
        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);