Java Code Examples for com.amazonaws.services.sqs.model.DeleteMessageBatchRequest#setQueueUrl()
The following examples show how to use
com.amazonaws.services.sqs.model.DeleteMessageBatchRequest#setQueueUrl() .
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: DeleteSQS.java From nifi with Apache License 2.0 | 5 votes |
@Override public void onTrigger(final ProcessContext context, final ProcessSession session) { FlowFile flowFile = session.get(); if (flowFile == null) { return; } final String queueUrl = context.getProperty(QUEUE_URL).evaluateAttributeExpressions(flowFile).getValue(); final AmazonSQSClient client = getClient(); final DeleteMessageBatchRequest request = new DeleteMessageBatchRequest(); request.setQueueUrl(queueUrl); final List<DeleteMessageBatchRequestEntry> entries = new ArrayList<>(); final DeleteMessageBatchRequestEntry entry = new DeleteMessageBatchRequestEntry(); String receiptHandle = context.getProperty(RECEIPT_HANDLE).evaluateAttributeExpressions(flowFile).getValue(); entry.setReceiptHandle(receiptHandle); String entryId = flowFile.getAttribute(CoreAttributes.UUID.key()); entry.setId(entryId); entries.add(entry); request.setEntries(entries); try { DeleteMessageBatchResult response = client.deleteMessageBatch(request); // check for errors if (!response.getFailed().isEmpty()) { throw new ProcessException(response.getFailed().get(0).toString()); } getLogger().info("Successfully deleted message from SQS for {}", new Object[] { flowFile }); session.transfer(flowFile, REL_SUCCESS); } catch (final Exception e) { getLogger().error("Failed to delete message from SQS due to {}", new Object[] { e }); flowFile = session.penalize(flowFile); session.transfer(flowFile, REL_FAILURE); return; } }
Example 2
Source File: AlertJanitor.java From s3mper with Apache License 2.0 | 5 votes |
private void delete(String queue, List<Message> messages) { List<DeleteMessageBatchRequestEntry> deleteRequests = new ArrayList<DeleteMessageBatchRequestEntry>(); for(Message m : messages) { deleteRequests.add(new DeleteMessageBatchRequestEntry().withId(m.getMessageId()).withReceiptHandle(m.getReceiptHandle())); } log.info(format("Deleting %s messages", deleteRequests.size())); DeleteMessageBatchRequest batchDelete = new DeleteMessageBatchRequest(); batchDelete.setQueueUrl(queue); batchDelete.setEntries(deleteRequests); sqs.deleteMessageBatch(batchDelete); }