Receives messages from the queue according to the arguments provided.

public static List<LrSqsMessage> receiveMessagesEx(Integer maxNumberOfMessages, Integer waitTimeSeconds, Integer visibilityTimeout, Collection<String> attributeNames, Collection<String> systemAttributeNames, String receiveRequestAttemptId)


maxNumberOfMessagesThe maximum number of messages to receive.
waitTimeSecondsThe maximum number of seconds to wait for the messages.
visibilityTimeoutThe number of seconds for which the received messages are hidden from subsequent requests.
attributeNamesThe keys of user-supplied message attributes to be retrieved for each message.
systemAttributeNamesThe keys of message metadata attributes to be retrieved for each message.
receiveRequestAttemptIdThe deduplication ID for ReceiveMessage calls.

Return values

This function returns a collection of LrSqsMessage elements.

General information

This function can receive one or more messages, depending on the maxNumberOfMessages argument.

The waitTimeSeconds argument is used to wait for messages if they are not available. This creates the long polling effect. For details about this effect, see the Amazon SQS documentation.

The receiveRequestAttemptId argument is used only for FIFO (first in first out) queues. If message retrieval fails, you can retry the retrieval with the same receive request attempt ID to retrieve the previous messages. If this argument is not supplied, an ID is auto-generated.

You can specify any number of messages to receive and any amount of time to wait. The function will send one or more requests, each attempting to receive at most 10 messages or waiting for at most 20 seconds.


Copy code
public void receiveMessageTest(){
        LrSqsClient.initClient(region, standardQueueUrl);
        LrSqsMessage message = LrSqsClient.receiveMessage();
        lr.output_message("Got 1 message: " + message.body());
        List<LrSqsMessage> collection = LrSqsClient.receiveMessages(5, 20);
        for (LrSqsMessage m : collection) {
            lr.output_message("Got message in colection: " + m.body());
        List<LrSqsMessage> collectionEx =   LrSqsClient.receiveMessagesEx(3, 20, null, null, new ArrayList() {{ add("MessageGroupId"); }}, null);
        for (LrSqsMessage m : collectionEx) {
            String messageGroupId = m.systemAttributesAsStrings().get("MessageGroupId");
            lr.log_message("Got message in colectionEX: " + messageGroupId + " " + m.body());
        LrSqsDeleteMessageBatchRequestStatus status = LrSqsClient.deleteMessageBatch(collectionEx);