com.amazonaws.services.sqs.model.ReceiptHandleIsInvalidException Java Examples

The following examples show how to use com.amazonaws.services.sqs.model.ReceiptHandleIsInvalidException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AmazonSQSIdleQueueDeletingClient.java    From amazon-sqs-java-temporary-queues-client with Apache License 2.0 6 votes vote down vote up
@Override
public DeleteMessageResult deleteMessage(DeleteMessageRequest request) {
    String queueUrl = request.getQueueUrl();
    try {
        heartbeatToQueueIfNecessary(queueUrl);
        return super.deleteMessage(request);
    } catch (QueueDoesNotExistException|ReceiptHandleIsInvalidException e) {
        try {
            return super.deleteMessage(
                    request.clone().withQueueUrl(alternateQueueName(request.getQueueUrl())));
        } catch (QueueDoesNotExistException e2) {
            // Silently fail - the message is definitely deleted after all!
            return new DeleteMessageResult();
        }
    }
}
 
Example #2
Source File: AmazonSQSIdleQueueDeletingClient.java    From amazon-sqs-java-temporary-queues-client with Apache License 2.0 5 votes vote down vote up
@Override
public ChangeMessageVisibilityResult changeMessageVisibility(ChangeMessageVisibilityRequest request) {
    // If the queue is deleted, there's no way to change the message visibility.
    try {
        return super.changeMessageVisibility(request);
    } catch (QueueDoesNotExistException|ReceiptHandleIsInvalidException e) {
        // Try on the alternate queue
        return super.changeMessageVisibility(
                request.clone().withQueueUrl(alternateQueueName(request.getQueueUrl())));
    }
}
 
Example #3
Source File: AmazonSQSIdleQueueDeletingClient.java    From amazon-sqs-java-temporary-queues-client with Apache License 2.0 5 votes vote down vote up
@Override
public ChangeMessageVisibilityBatchResult changeMessageVisibilityBatch(ChangeMessageVisibilityBatchRequest request) {
    // If the queue is deleted, there's no way to change the message visibility.
    try {
        return super.changeMessageVisibilityBatch(request);
    } catch (QueueDoesNotExistException|ReceiptHandleIsInvalidException e) {
        // Try on the alternate queue
        ChangeMessageVisibilityBatchRequest alternateRequest = request.clone().withQueueUrl(alternateQueueName(request.getQueueUrl()));
        return super.changeMessageVisibilityBatch(alternateRequest);
    }
}
 
Example #4
Source File: AmazonSQSStubTest.java    From aws-java-sdk-stubs with Apache License 2.0 5 votes vote down vote up
@Test
public void deleteMessageSucceedsWithValidReceiptHandle() {
  final String queueName = "bizo";
  final String messageBody = "hi everybody";

  final CreateQueueRequest createQueueRequest = new CreateQueueRequest().withQueueName(queueName);
  sqs.createQueue(createQueueRequest);

  final GetQueueUrlRequest getQueueUrlRequest = new GetQueueUrlRequest().withQueueName(queueName);
  final GetQueueUrlResult getQueueUrlResult = sqs.getQueueUrl(getQueueUrlRequest);
  final String queueUrl = getQueueUrlResult.getQueueUrl();

  final SendMessageRequest sendMessageRequest =
    new SendMessageRequest().withQueueUrl(queueUrl).withMessageBody(messageBody);
  sqs.sendMessage(sendMessageRequest);

  final int maxNumberOfMessages = 10;

  final ReceiveMessageRequest receiveMessageRequest =
    new ReceiveMessageRequest().withQueueUrl(queueUrl).withMaxNumberOfMessages(maxNumberOfMessages);
  final ReceiveMessageResult receiveMessageResult = sqs.receiveMessage(receiveMessageRequest);
  final List<Message> messages = receiveMessageResult.getMessages();
  assertThat(messages.size(), equalTo(1));

  final String receiptHandle = messages.get(0).getReceiptHandle();
  final DeleteMessageRequest deleteMessageRequest =
    new DeleteMessageRequest().withQueueUrl(queueUrl).withReceiptHandle(receiptHandle);

  try {
    sqs.deleteMessage(deleteMessageRequest);
  } catch (ReceiptHandleIsInvalidException e) {
    fail("ReceiptHandleIsInvalidException was thrown");
  }
}
 
Example #5
Source File: AmazonSQSStubTest.java    From aws-java-sdk-stubs with Apache License 2.0 5 votes vote down vote up
@Test(expected = ReceiptHandleIsInvalidException.class)
public void deleteMessageFailsWithInvalidReceiptHandle() {
  final String queueName = "bizo";
  final String messageBody = "hi everybody";

  final CreateQueueRequest createQueueRequest = new CreateQueueRequest().withQueueName(queueName);
  sqs.createQueue(createQueueRequest);

  final GetQueueUrlRequest getQueueUrlRequest = new GetQueueUrlRequest().withQueueName(queueName);
  final GetQueueUrlResult getQueueUrlResult = sqs.getQueueUrl(getQueueUrlRequest);
  final String queueUrl = getQueueUrlResult.getQueueUrl();

  final SendMessageRequest sendMessageRequest =
    new SendMessageRequest().withQueueUrl(queueUrl).withMessageBody(messageBody);
  sqs.sendMessage(sendMessageRequest);

  final ReceiveMessageRequest receiveMessageRequest = new ReceiveMessageRequest().withQueueUrl(queueUrl);
  final ReceiveMessageResult receiveMessageResult = sqs.receiveMessage(receiveMessageRequest);
  final List<Message> messages = receiveMessageResult.getMessages();
  assertThat(messages.size(), equalTo(1));

  final String receiptHandle = "bizo";
  final DeleteMessageRequest deleteMessageRequest =
    new DeleteMessageRequest().withQueueUrl(queueUrl).withReceiptHandle(receiptHandle);

  sqs.deleteMessage(deleteMessageRequest);
}
 
Example #6
Source File: AmazonMessageAcknowledger.java    From echo with Apache License 2.0 5 votes vote down vote up
@Override
public void ack() {
  // Delete from queue
  try {
    amazonSQS.deleteMessage(queueUrl, message.getReceiptHandle());
    registry.counter(getProcessedMetricId(subscriptionName)).increment();
  } catch (ReceiptHandleIsInvalidException e) {
    log.warn(
        "Error deleting message: {}, queue: {}, reason: {} (receiptHandle: {})",
        message.getMessageId(),
        queueUrl,
        e.getMessage(),
        message.getReceiptHandle());
  }
}
 
Example #7
Source File: DefaultAmazonMessageAcknowledger.java    From kork with Apache License 2.0 5 votes vote down vote up
@Override
public void ack(AmazonSubscriptionInformation subscription, Message message) {
  // Delete from queue
  try {
    subscription.amazonSQS.deleteMessage(subscription.queueUrl, message.getReceiptHandle());
    registry.counter(getSuccessCounter(subscription)).increment();
  } catch (ReceiptHandleIsInvalidException e) {
    log.warn(
        "Error deleting message: {}, subscription: {}", message.getMessageId(), subscription, e);
    registry.counter(getErrorCounter(subscription, e)).increment();
  }
}
 
Example #8
Source File: TemporarySQSQueue.java    From front50 with Apache License 2.0 5 votes vote down vote up
void markMessageAsHandled(String receiptHandle) {
  try {
    amazonSQS.deleteMessage(temporaryQueue.sqsQueueUrl, receiptHandle);
  } catch (ReceiptHandleIsInvalidException e) {
    log.warn(
        "Error deleting message, reason: {} (receiptHandle: {})",
        e.getMessage(),
        value("receiptHandle", receiptHandle));
  }
}