/** * Simplified method form for invoking the ChangeMessageVisibility * operation. * * @see #changeMessageVisibility(ChangeMessageVisibilityRequest) */ public ChangeMessageVisibilityResult changeMessageVisibility(String queueUrl, String receiptHandle, Integer visibilityTimeout) { ChangeMessageVisibilityRequest changeMessageVisibilityRequest = new ChangeMessageVisibilityRequest(queueUrl, receiptHandle, visibilityTimeout); return changeMessageVisibility(changeMessageVisibilityRequest); }
@Override public ChangeMessageVisibilityResult changeMessageVisibility(ChangeMessageVisibilityRequest changeMessageVisibilityRequest) throws AmazonClientException { try { DirectorySQSQueue queue = getQueueFromUrl(changeMessageVisibilityRequest.getQueueUrl(), false); queue.changeVisibility(changeMessageVisibilityRequest.getReceiptHandle(), changeMessageVisibilityRequest.getVisibilityTimeout()); return new ChangeMessageVisibilityResult(); } catch (IOException e) { throw new AmazonServiceException("error", e); } }
@Test public void testSendChangeVisibilityReceiveDeleteMessage_shouldSendChangeVisibilityReceiveAndDeleteMessage() { // create queue CreateQueueResult createdQueue = sqs.createQueue(new CreateQueueRequest().withQueueName("tea-earl-grey-queue")); // send message String messageBody = "{\"life-universe-everything\":42}"; SendMessageResult sendResult = sqs.sendMessage(new SendMessageRequest().withDelaySeconds(0).withMessageBody(messageBody) .withMessageGroupId("some-group-id-123").withQueueUrl(createdQueue.getQueueUrl())); assertNotNull("message sending returned ok", sendResult); assertNotNull("verify body MD5 exists",sendResult.getMD5OfMessageBody()); assertNotNull("verify message id exists",sendResult.getMessageId()); // receive message ReceiveMessageResult messageResult = sqs.receiveMessage(new ReceiveMessageRequest() .withMaxNumberOfMessages(3).withQueueUrl(createdQueue.getQueueUrl()).withVisibilityTimeout(10) .withWaitTimeSeconds(0)); assertNotNull("verify received message returned ok",messageResult); assertEquals("verify correct receive count", 1, messageResult.getMessages().size()); Message firstMessage = messageResult.getMessages().get(0); assertEquals("verify correct body returned",messageBody,firstMessage.getBody()); assertEquals("verify correct message MD5",getAwsMessageMD5(messageBody),firstMessage.getMD5OfBody()); assertNotNull("verify message id exists",firstMessage.getMessageId()); assertNotNull("verify receipt handle exists",firstMessage.getReceiptHandle()); // extend visibility timeout ChangeMessageVisibilityResult visibilityResult = sqs.changeMessageVisibility(new ChangeMessageVisibilityRequest() .withQueueUrl(createdQueue.getQueueUrl()).withReceiptHandle(firstMessage.getReceiptHandle()).withVisibilityTimeout(40)); assertNotNull("changing visibility returned ok", visibilityResult); // verify if message is invisible ReceiveMessageResult emptyResult = sqs.receiveMessage(new ReceiveMessageRequest() .withMaxNumberOfMessages(1).withQueueUrl(createdQueue.getQueueUrl()).withVisibilityTimeout(20) .withWaitTimeSeconds(0)); assertTrue("at visibility timeout the message should not be available.", emptyResult.getMessages().isEmpty()); // delete message from queue DeleteMessageResult deleteResult = sqs.deleteMessage(new DeleteMessageRequest() .withQueueUrl(createdQueue.getQueueUrl()).withReceiptHandle(firstMessage.getReceiptHandle())); assertNotNull("verify deletion returned ok",deleteResult); assertTrue("queue must be empty after removal",getQueues().get("tea-earl-grey-queue").getMessageQueue().isEmpty()); assertTrue("invisibility-queue must be empty after removal",getQueues().get("tea-earl-grey-queue").getInvisibilityQueueFor(firstMessage.getReceiptHandle()).isEmpty()); // cleanup getQueues().remove("tea-earl-grey-queue"); }
public Observable<ChangeMessageVisibilityResult> changeMessageVisibilityAsync(ChangeMessageVisibilityRequest request) { return Observable.from(sqsClient.changeMessageVisibilityAsync(request)); }
public Observable<ChangeMessageVisibilityResult> changeMessageVisibilityAsync(String queueUrl, String receiptHandle, Integer visibilityTimeout) { return Observable.from(sqsClient.changeMessageVisibilityAsync(queueUrl, receiptHandle, visibilityTimeout)); }
@Override public ChangeMessageVisibilityResult changeMessageVisibility(ChangeMessageVisibilityRequest changeMessageVisibilityRequest) throws AmazonServiceException, AmazonClientException { this.changeMessageVisibilityRequests.add(changeMessageVisibilityRequest); return new ChangeMessageVisibilityResult(); }
/** * <p> * Changes the visibility timeout of a specified message in a queue to a new * value. The maximum allowed timeout value you can set the value to is 12 * hours. This means you can't extend the timeout of a message in an * existing queue to more than a total visibility timeout of 12 hours. (For * more information visibility timeout, see <a href= * "http://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/AboutVT.html" * > Visibility Timeout </a> in the <i>Amazon SQS Developer Guide</i> .) * </p> * <p> * For example, let's say you have a message and its default message * visibility timeout is 30 minutes. You could call * <code>ChangeMessageVisiblity</code> with a value of two hours and the * effective timeout would be two hours and 30 minutes. When that time comes * near you could again extend the time out by calling * ChangeMessageVisiblity, but this time the maximum allowed timeout would * be 9 hours and 30 minutes. * </p> * <p> * <b>NOTE:</b> There is a 120,000 limit for the number of inflight messages * per queue. Messages are inflight after they have been received from the * queue by a consuming component, but have not yet been deleted from the * queue. If you reach the 120,000 limit, you will receive an OverLimit * error message from Amazon SQS. To help avoid reaching the limit, you * should delete the messages from the queue after they have been processed. * You can also increase the number of queues you use to process the * messages. * </p> * <p> * <b>IMPORTANT:</b>If you attempt to set the VisibilityTimeout to an amount * more than the maximum time left, Amazon SQS returns an error. It will not * automatically recalculate and increase the timeout to the maximum time * remaining. * </p> * <p> * <b>IMPORTANT:</b>Unlike with a queue, when you change the visibility * timeout for a specific message, that timeout value is applied immediately * but is not saved in memory for that message. If you don't delete a * message after it is received, the visibility timeout for the message the * next time it is received reverts to the original timeout value, not the * value you set with the ChangeMessageVisibility action. * </p> * * @param changeMessageVisibilityRequest * Container for the necessary parameters to execute the * ChangeMessageVisibility service method on AmazonSQS. * * * @throws ReceiptHandleIsInvalidException * @throws MessageNotInflightException * * @throws AmazonClientException * If any internal errors are encountered inside the client * while attempting to make the request or handle the response. * For example if a network connection is not available. * @throws AmazonServiceException * If an error response is returned by AmazonSQS indicating * either a problem with the data in the request, or a server * side issue. */ public ChangeMessageVisibilityResult changeMessageVisibility(ChangeMessageVisibilityRequest changeMessageVisibilityRequest) throws AmazonServiceException, AmazonClientException { if (isS3ReceiptHandle(changeMessageVisibilityRequest.getReceiptHandle())) { changeMessageVisibilityRequest.setReceiptHandle( getOrigReceiptHandle(changeMessageVisibilityRequest.getReceiptHandle())); } return amazonSqsToBeExtended.changeMessageVisibility(changeMessageVisibilityRequest); }
/** * <p> * Changes the visibility timeout of a specified message in a queue to a new * value. The maximum allowed timeout value you can set the value to is 12 * hours. This means you can't extend the timeout of a message in an * existing queue to more than a total visibility timeout of 12 hours. (For * more information visibility timeout, see <a href= * "http://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/AboutVT.html" * > Visibility Timeout </a> in the <i>Amazon SQS Developer Guide</i> .) * </p> * <p> * For example, let's say you have a message and its default message * visibility timeout is 30 minutes. You could call * <code>ChangeMessageVisiblity</code> with a value of two hours and the * effective timeout would be two hours and 30 minutes. When that time comes * near you could again extend the time out by calling * ChangeMessageVisiblity, but this time the maximum allowed timeout would * be 9 hours and 30 minutes. * </p> * <p> * <b>NOTE:</b> There is a 120,000 limit for the number of inflight messages * per queue. Messages are inflight after they have been received from the * queue by a consuming component, but have not yet been deleted from the * queue. If you reach the 120,000 limit, you will receive an OverLimit * error message from Amazon SQS. To help avoid reaching the limit, you * should delete the messages from the queue after they have been processed. * You can also increase the number of queues you use to process the * messages. * </p> * <p> * <b>IMPORTANT:</b>If you attempt to set the VisibilityTimeout to an amount * more than the maximum time left, Amazon SQS returns an error. It will not * automatically recalculate and increase the timeout to the maximum time * remaining. * </p> * <p> * <b>IMPORTANT:</b>Unlike with a queue, when you change the visibility * timeout for a specific message, that timeout value is applied immediately * but is not saved in memory for that message. If you don't delete a * message after it is received, the visibility timeout for the message the * next time it is received reverts to the original timeout value, not the * value you set with the ChangeMessageVisibility action. * </p> * * @param changeMessageVisibilityRequest * Container for the necessary parameters to execute the * ChangeMessageVisibility service method on AmazonSQS. * * * @throws ReceiptHandleIsInvalidException * @throws MessageNotInflightException * * @throws AmazonClientException * If any internal errors are encountered inside the client * while attempting to make the request or handle the response. * For example if a network connection is not available. * @throws AmazonServiceException * If an error response is returned by AmazonSQS indicating * either a problem with the data in the request, or a server * side issue. */ public ChangeMessageVisibilityResult changeMessageVisibility(ChangeMessageVisibilityRequest changeMessageVisibilityRequest) throws AmazonServiceException, AmazonClientException { return amazonSqsToBeExtended.changeMessageVisibility(changeMessageVisibilityRequest); }
/** * <p> * Changes the visibility timeout of a specified message in a queue to a new * value. The maximum allowed timeout value you can set the value to is 12 * hours. This means you can't extend the timeout of a message in an * existing queue to more than a total visibility timeout of 12 hours. (For * more information visibility timeout, see <a href= * "http://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/AboutVT.html" * > Visibility Timeout </a> in the <i>Amazon SQS Developer Guide</i> .) * </p> * <p> * For example, let's say you have a message and its default message * visibility timeout is 30 minutes. You could call * <code>ChangeMessageVisiblity</code> with a value of two hours and the * effective timeout would be two hours and 30 minutes. When that time comes * near you could again extend the time out by calling * ChangeMessageVisiblity, but this time the maximum allowed timeout would * be 9 hours and 30 minutes. * </p> * <p> * <b>NOTE:</b> There is a 120,000 limit for the number of inflight messages * per queue. Messages are inflight after they have been received from the * queue by a consuming component, but have not yet been deleted from the * queue. If you reach the 120,000 limit, you will receive an OverLimit * error message from Amazon SQS. To help avoid reaching the limit, you * should delete the messages from the queue after they have been processed. * You can also increase the number of queues you use to process the * messages. * </p> * <p> * <b>IMPORTANT:</b>If you attempt to set the VisibilityTimeout to an amount * more than the maximum time left, Amazon SQS returns an error. It will not * automatically recalculate and increase the timeout to the maximum time * remaining. * </p> * <p> * <b>IMPORTANT:</b>Unlike with a queue, when you change the visibility * timeout for a specific message, that timeout value is applied immediately * but is not saved in memory for that message. If you don't delete a * message after it is received, the visibility timeout for the message the * next time it is received reverts to the original timeout value, not the * value you set with the ChangeMessageVisibility action. * </p> * * @param queueUrl * The URL of the Amazon SQS queue to take action on. * @param receiptHandle * The receipt handle associated with the message whose * visibility timeout should be changed. This parameter is * returned by the <a>ReceiveMessage</a> action. * @param visibilityTimeout * The new value (in seconds - from 0 to 43200 - maximum 12 * hours) for the message's visibility timeout. * * @return The response from the ChangeMessageVisibility service method, as * returned by AmazonSQS. * * @throws ReceiptHandleIsInvalidException * @throws MessageNotInflightException * * @throws AmazonClientException * If any internal errors are encountered inside the client * while attempting to make the request or handle the response. * For example if a network connection is not available. * @throws AmazonServiceException * If an error response is returned by AmazonSQS indicating * either a problem with the data in the request, or a server * side issue. */ public ChangeMessageVisibilityResult changeMessageVisibility(String queueUrl, String receiptHandle, Integer visibilityTimeout) throws AmazonServiceException, AmazonClientException { return amazonSqsToBeExtended.changeMessageVisibility(queueUrl, receiptHandle, visibilityTimeout); }