Example usage for com.amazonaws.services.sqs.model DeleteMessageRequest getReceiptHandle

List of usage examples for com.amazonaws.services.sqs.model DeleteMessageRequest getReceiptHandle

Introduction

In this page you can find the example usage for com.amazonaws.services.sqs.model DeleteMessageRequest getReceiptHandle.

Prototype


public String getReceiptHandle() 

Source Link

Document

The receipt handle associated with the message to delete.

Usage

From source file:com.amazon.sqs.javamessaging.AmazonSQSExtendedClient.java

License:Open Source License

/**
 * <p>//from  www .j  a va 2 s .c  o  m
 * Deletes the specified message from the specified queue and deletes the
 * message payload from Amazon S3 when necessary. You specify the message by
 * using the message's <code>receipt handle</code> and not the
 * <code>message ID</code> you received when you sent the message. Even if
 * the message is locked by another reader due to the visibility timeout
 * setting, it is still deleted from the queue. If you leave a message in
 * the queue for longer than the queue's configured retention period, Amazon
 * SQS automatically deletes it.
 * </p>
 * <p>
 * <b>NOTE:</b> The receipt handle is associated with a specific instance of
 * receiving the message. If you receive a message more than once, the
 * receipt handle you get each time you receive the message is different.
 * When you request DeleteMessage, if you don't provide the most recently
 * received receipt handle for the message, the request will still succeed,
 * but the message might not be deleted.
 * </p>
 * <p>
 * <b>IMPORTANT:</b> It is possible you will receive a message even after
 * you have deleted it. This might happen on rare occasions if one of the
 * servers storing a copy of the message is unavailable when you request to
 * delete the message. The copy remains on the server and might be returned
 * to you again on a subsequent receive request. You should create your
 * system to be idempotent so that receiving a particular message more than
 * once is not a problem.
 * </p>
 *
 * @param deleteMessageRequest
 *            Container for the necessary parameters to execute the
 *            DeleteMessage service method on AmazonSQS.
 * 
 * 
 * @throws ReceiptHandleIsInvalidException
 * @throws InvalidIdFormatException
 *
 * @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 void deleteMessage(DeleteMessageRequest deleteMessageRequest) {

    if (deleteMessageRequest == null) {
        String errorMessage = "deleteMessageRequest cannot be null.";
        LOG.error(errorMessage);
        throw new AmazonClientException(errorMessage);
    }

    deleteMessageRequest.getRequestClientOptions()
            .appendUserAgent(SQSExtendedClientConstants.USER_AGENT_HEADER);

    if (!clientConfiguration.isLargePayloadSupportEnabled()) {
        super.deleteMessage(deleteMessageRequest);
        return;
    }

    String receiptHandle = deleteMessageRequest.getReceiptHandle();
    String origReceiptHandle = receiptHandle;
    if (isS3ReceiptHandle(receiptHandle)) {
        deleteMessagePayloadFromS3(receiptHandle);
        origReceiptHandle = getOrigReceiptHandle(receiptHandle);
    }
    deleteMessageRequest.setReceiptHandle(origReceiptHandle);
    super.deleteMessage(deleteMessageRequest);
}

From source file:org.apache.camel.component.aws.sqs.AmazonSQSClientMock.java

License:Apache License

@Override
public void deleteMessage(DeleteMessageRequest deleteMessageRequest) throws AmazonClientException {
    String receiptHandle = deleteMessageRequest.getReceiptHandle();
    if (inFlight.containsKey(receiptHandle)) {
        ScheduledFuture inFlightTask = inFlight.get(receiptHandle);
        inFlightTask.cancel(true);/*  www . j av  a2s . co  m*/
    }
}

From source file:org.flite.mock.amazonaws.sqs.AmazonSQSMock.java

License:Open Source License

public void deleteMessage(final DeleteMessageRequest request)
        throws AmazonServiceException, AmazonClientException {
    if (request == null) {
        throw new AmazonClientException("Null DeleteMessageRequest");
    }//from  ww  w .j  av  a  2  s. c  om
    final String queueUrl = request.getQueueUrl();
    checkURLForException(queueUrl);
    checkStringForExceptionMarker(request.getReceiptHandle());
    // Ignoring the documented exception: InvalidIdFormatException
    if (!allQueues.containsKey(queueUrl)) {
        throw new AmazonServiceException("Queue Not Found: " + queueUrl);
    }
    if (!retrievedMessages.containsKey(queueUrl)) {
        throw new AmazonServiceException("Queue Not Found: " + queueUrl);
    }
    if (!retrievedMessages.get(queueUrl).containsKey(request.getReceiptHandle())) {
        throw new ReceiptHandleIsInvalidException("Reciept Handle Not Found: " + request.getReceiptHandle());
    }
    retrievedMessages.get(queueUrl).remove(request.getReceiptHandle());
}

From source file:smartthings.brave.sqs.AmazonSQSClientParser.java

License:Apache License

public void request(DeleteMessageRequest request, SpanCustomizer customizer) {
    customizer.name(spanName(request));//from ww w.ja  v a 2 s.co  m
    customizer.tag(AmazonSQSTraceKeys.SQS_QUEUE_URL, request.getQueueUrl());
    customizer.tag(AmazonSQSTraceKeys.SQS_RECEIPT_HANDLE, request.getReceiptHandle());
}