Share this page

# LrSqsClient.receiveMessagesEx

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)`

## Arguments

Name | Description
--- | ---
maxNumberOfMessages | The maximum number of messages to receive.
waitTimeSeconds | The maximum number of seconds to wait for the messages.
visibilityTimeout | The number of seconds for which the received messages are hidden from subsequent requests.
attributeNames | The keys of user-supplied message attributes to be retrieved for each message.
systemAttributeNames | The keys of message metadata attributes to be retrieved for each message.
receiveRequestAttemptId | The 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.

## Example

Copy code

    public void receiveMessageTest(){

            LrSqsClient.initClient(region, standardQueueUrl);

            LrSqsMessage message = LrSqsClient.receiveMessage();
            lr.output_message("Got 1 message: " + message.body());
            LrSqsClient.deleteMessage(message.receiptHandle());

            List<LrSqsMessage> collection = LrSqsClient.receiveMessages(5, 20);
            for (LrSqsMessage m : collection) {
                lr.output_message("Got message in collection: " + m.body());
                LrSqsClient.deleteMessage(m);
            }

            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 collectionEX: " + messageGroupId + " " + m.body());
            }

            LrSqsDeleteMessageBatchRequestStatus status = LrSqsClient.deleteMessageBatch(collectionEx);

            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: