List of usage examples for com.amazonaws.services.sqs.model DeleteMessageBatchRequestEntry setReceiptHandle
public void setReceiptHandle(String receiptHandle)
A receipt handle.
From source file:com.amazon.sqs.javamessaging.AmazonSQSExtendedClient.java
License:Open Source License
/** * <p>//from ww w. ja v a 2 s.com * Deletes up to ten messages from the specified queue. This is a batch * version of DeleteMessage. The result of the delete action on each message * is reported individually in the response. Also deletes the message * payloads from Amazon S3 when necessary. * </p> * <p> * <b>IMPORTANT:</b> Because the batch request can result in a combination * of successful and unsuccessful actions, you should check for batch errors * even when the call returns an HTTP status code of 200. * </p> * <p> * <b>NOTE:</b>Some API actions take lists of parameters. These lists are * specified using the param.n notation. Values of n are integers starting * from 1. For example, a parameter list with two elements looks like this: * </p> * <p> * <code>&Attribute.1=this</code> * </p> * <p> * <code>&Attribute.2=that</code> * </p> * * @param deleteMessageBatchRequest * Container for the necessary parameters to execute the * DeleteMessageBatch service method on AmazonSQS. * * @return The response from the DeleteMessageBatch service method, as * returned by AmazonSQS. * * @throws BatchEntryIdsNotDistinctException * @throws TooManyEntriesInBatchRequestException * @throws InvalidBatchEntryIdException * @throws EmptyBatchRequestException * * @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 DeleteMessageBatchResult deleteMessageBatch(DeleteMessageBatchRequest deleteMessageBatchRequest) { if (deleteMessageBatchRequest == null) { String errorMessage = "deleteMessageBatchRequest cannot be null."; LOG.error(errorMessage); throw new AmazonClientException(errorMessage); } deleteMessageBatchRequest.getRequestClientOptions() .appendUserAgent(SQSExtendedClientConstants.USER_AGENT_HEADER); if (!clientConfiguration.isLargePayloadSupportEnabled()) { return super.deleteMessageBatch(deleteMessageBatchRequest); } for (DeleteMessageBatchRequestEntry entry : deleteMessageBatchRequest.getEntries()) { String receiptHandle = entry.getReceiptHandle(); String origReceiptHandle = receiptHandle; if (isS3ReceiptHandle(receiptHandle)) { deleteMessagePayloadFromS3(receiptHandle); origReceiptHandle = getOrigReceiptHandle(receiptHandle); } entry.setReceiptHandle(origReceiptHandle); } return super.deleteMessageBatch(deleteMessageBatchRequest); }
From source file:com.pinterest.teletraan.worker.LaunchEventCollector.java
License:Apache License
public void collectEvents() throws Exception { while (true) { ReceiveMessageRequest request = new ReceiveMessageRequest(); request.setMaxNumberOfMessages(10); ReceiveMessageResult result = sqsClient.receiveMessage(request); List<Message> messageList = result.getMessages(); if (messageList.isEmpty()) { LOG.info("No more Launch activity available at the moment."); return; }//from w w w . j a va2s. co m LOG.info(String.format("Collect %d events from AWS SQS.", messageList.size())); ArrayList<DeleteMessageBatchRequestEntry> entries = new ArrayList<>(); for (Message message : messageList) { try { boolean hasProcessed = processMessage(message); if (hasProcessed) { DeleteMessageBatchRequestEntry entry = new DeleteMessageBatchRequestEntry(); entry.setId(message.getMessageId()); entry.setReceiptHandle(message.getReceiptHandle()); entries.add(entry); } } catch (Exception ex) { LOG.error("Failed to process SQS message:", message, ex); } } if (!entries.isEmpty()) { DeleteMessageBatchRequest deleteMessageBatchRequest = new DeleteMessageBatchRequest(); deleteMessageBatchRequest.setEntries(entries); LOG.debug(String.format("Successful process %d messages, deleting them from SQS.", entries.size())); sqsClient.deleteMessageBatch(deleteMessageBatchRequest); } } }
From source file:org.apache.nifi.processors.aws.sqs.DeleteSQS.java
License:Apache License
@Override public void onTrigger(final ProcessContext context, final ProcessSession session) { List<FlowFile> flowFiles = session.get(1); if (flowFiles.isEmpty()) { return;/*from w w w .j av a 2 s . co m*/ } final FlowFile firstFlowFile = flowFiles.get(0); final String queueUrl = context.getProperty(QUEUE_URL).evaluateAttributeExpressions(firstFlowFile) .getValue(); final AmazonSQSClient client = getClient(); final DeleteMessageBatchRequest request = new DeleteMessageBatchRequest(); request.setQueueUrl(queueUrl); final List<DeleteMessageBatchRequestEntry> entries = new ArrayList<>(flowFiles.size()); for (final FlowFile flowFile : flowFiles) { final DeleteMessageBatchRequestEntry entry = new DeleteMessageBatchRequestEntry(); entry.setReceiptHandle( context.getProperty(RECEIPT_HANDLE).evaluateAttributeExpressions(flowFile).getValue()); entries.add(entry); } request.setEntries(entries); try { client.deleteMessageBatch(request); getLogger().info("Successfully deleted {} objects from SQS", new Object[] { flowFiles.size() }); session.transfer(flowFiles, REL_SUCCESS); } catch (final Exception e) { getLogger().error("Failed to delete {} objects from SQS due to {}", new Object[] { flowFiles.size(), e }); final List<FlowFile> penalizedFlowFiles = new ArrayList<>(); for (final FlowFile flowFile : flowFiles) { penalizedFlowFiles.add(session.penalize(flowFile)); } session.transfer(penalizedFlowFiles, REL_FAILURE); } }