Share this page

# LrSqsClient.changeMessageVisibility

Changes a message's visibility timeout.

`public static void changeMessageVisibility(String receiptHandle, int visibilityTimeout)`

## Arguments

Name | Description
--- | ---
receiptHandle | The handle contained within the LrSqsMessage.
visibilityTimeout | The new VisibilityTimeout value.

## Return values

This function does not return any values.

## General information

Message visibility is an AWS mechanism that prevents a client from receiving the same message multiple times. When the client receives a message, it is not automatically deleted from the queue. Therefore, a client could call one of the receiveMessage APIs and receive the same message again. To prevent this, SQS makes the message “invisible” to clients for a period of time after being received by a client.

## Example

Copy code

    public void changeVisibility() {

            LrSqsClient.initClient(region, standardQueueUrl);

            LrSqsClient.initMessageBatch();
            LrSqsClient.addMessageToBatch("m1");
            LrSqsClient.addMessageToBatch("m2");
            LrSqsClient.addMessageToBatch("m3");
            LrSqsClient.addMessageToBatch("m4");
            LrSqsClient.sendMessageBatch();

            LrSqsMessage message1 = LrSqsClient.receiveMessage();
            if (message1 != null){
                LrSqsClient.changeMessageVisibility(message1.receiptHandle(), 20);
            }
            List <LrSqsMessage> receivedMessages = LrSqsClient.receiveMessages(3, 20);

            LrSqsClient.initChangeMessageVisibilityBatch();
            int visibilityTimeout = 10;
            for (LrSqsMessage m : receivedMessages) {
                //LrSqsClient.addMessageToChangeVisibilityBatch(m, visibilityTimeout);
                LrSqsClient.addReceiptHandleToChangeVisibilityBatch(m.receiptHandle(), visibilityTimeout);
                visibilityTimeout += 2;
            }
            LrSqsClient.changeMessageVisibilityBatch();

            LrSqsClient.closeClient();
        }

Tips to improve your search results... VuGen Function Reference Version 26.1-26.3 Function Reference 26.1-26.3 All View Local Help Center View Online Help Center Version: