Share this page

# LrSqsClient.receiveMessage

Receives messages from the queue.

`public static LrSqsMessage receiveMessage()`

`public static List<LrSqsMessage> receiveMessages(int maxNumberOfMessages)`

`public static List<LrSqsMessage> receiveMessages(int maxNumberOfMessages, int waitTimeSeconds)`

## Arguments

Name | Description
--- | ---
maxNumberOfMessages | The maximum number of messages to receive.
waitTimeSeconds | The maximum number of seconds to wait for the messages.

## Return values

This function returns an LrSqsMessage object or a list of LrSqsMessage objects. If the queue is empty and there are no messages to be retrieved, the returned value is null.

## General information

If no arguments are used for this API, the function retrieves only one message.

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

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 26.1 Function Reference 26.1 All View Local Help Center View Online Help Center Version: