com.amazonaws.services.sqs.model.DeleteMessageBatchRequestEntry Java Examples
The following examples show how to use
com.amazonaws.services.sqs.model.DeleteMessageBatchRequestEntry.
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: SQSObservableQueue.java From conductor with Apache License 2.0 | 6 votes |
private List<String> delete(List<Message> messages) { if (messages == null || messages.isEmpty()) { return null; } DeleteMessageBatchRequest batch = new DeleteMessageBatchRequest().withQueueUrl(queueURL); List<DeleteMessageBatchRequestEntry> entries = batch.getEntries(); messages.forEach(m -> entries.add(new DeleteMessageBatchRequestEntry().withId(m.getId()).withReceiptHandle(m.getReceipt()))); DeleteMessageBatchResult result = client.deleteMessageBatch(batch); List<String> failures = result.getFailed().stream() .map(BatchResultErrorEntry::getId) .collect(Collectors.toList()); logger.debug("Failed to delete messages from queue: {}: {}", queueName, failures); return failures; }
Example #2
Source File: SQSScanWorkflow.java From emodb with Apache License 2.0 | 6 votes |
@Override public void releaseCompleteScanRanges(Collection<ScanRangeComplete> completions) { if (completions.isEmpty()) { return; } int id = 0; List<DeleteMessageBatchRequestEntry> entries = Lists.newArrayListWithCapacity(completions.size()); for (ScanRangeComplete completion : completions) { entries.add( new DeleteMessageBatchRequestEntry() .withId(String.valueOf(id++)) .withReceiptHandle(((QueueScanRangeComplete) completion).getMessageId())); } _sqs.deleteMessageBatch(new DeleteMessageBatchRequest() .withQueueUrl(getQueueUrl(_completeScanRangeQueue)) .withEntries(entries)); }
Example #3
Source File: SQSResourcesIntegrationTest.java From aws-sdk-java-resources with Apache License 2.0 | 6 votes |
/** * Tests a simple send, receive and delete of a message from the queue * resource. Asserts the message contents and its associated attributes. */ @Test @Ignore public void testSendReceiveDelete() throws InterruptedException { SendMessageResult sendMessageResult = queue.sendMessage(TEST_MESSAGE); assertNotNull(sendMessageResult); assertNotNull(sendMessageResult.getMessageId()); List<Message> messages = waitForMessagesFromQueue(null); assertNotNull(messages); assertEquals(1, messages.size()); Message message = messages.get(0); assertMessage(TEST_MESSAGE, sendMessageResult.getMessageId(), sendMessageResult.getMD5OfMessageBody(), message); queue.deleteMessages(new DeleteMessageBatchRequest() .withEntries(new DeleteMessageBatchRequestEntry("msg1", message .getReceiptHandle()))); }
Example #4
Source File: RequestFactoryImpl.java From aws-codecommit-trigger-plugin with Apache License 2.0 | 5 votes |
@Override public DeleteMessageBatchRequest createDeleteMessageBatchRequest(String queueUrl, List<Message> messages) { final List<DeleteMessageBatchRequestEntry> entries = new ArrayList<>(messages.size()); for (final Message message : messages) { final DeleteMessageBatchRequestEntry entry = this.createDeleteMessageBatchRequestEntry(message); entries.add(entry); } final DeleteMessageBatchRequest request = new DeleteMessageBatchRequest(queueUrl); request.setEntries(entries); return request; }
Example #5
Source File: SQSSpanProcessor.java From zipkin-aws with Apache License 2.0 | 5 votes |
private void process(final List<Message> messages) { if (messages.size() == 0) return; final List<DeleteMessageBatchRequestEntry> toDelete = new ArrayList<>(); int count = 0; for (Message message : messages) { final String deleteId = String.valueOf(count++); try { String stringBody = message.getBody(); if (stringBody.isEmpty() || stringBody.equals("[]")) continue; // allow plain-text json, but permit base64 encoded thrift or json byte[] serialized = stringBody.charAt(0) == '[' ? stringBody.getBytes(UTF_8) : Base64.decode(stringBody); metrics.incrementMessages(); metrics.incrementBytes(serialized.length); collector.acceptSpans( serialized, new Callback<Void>() { @Override public void onSuccess(Void value) { toDelete.add( new DeleteMessageBatchRequestEntry(deleteId, message.getReceiptHandle())); } @Override public void onError(Throwable t) { logger.log(Level.WARNING, "collector accept failed", t); // for cases that are not recoverable just discard the message, // otherwise ignore so processing can be retried. if (t instanceof IllegalArgumentException) { toDelete.add( new DeleteMessageBatchRequestEntry(deleteId, message.getReceiptHandle())); } } }); } catch (RuntimeException | Error e) { logger.log(Level.WARNING, "message decoding failed", e); toDelete.add(new DeleteMessageBatchRequestEntry(deleteId, message.getReceiptHandle())); } } if (!toDelete.isEmpty()) { delete(toDelete); } }
Example #6
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); }
Example #7
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 #8
Source File: RangedAcknowledger.java From amazon-sqs-java-messaging-lib with Apache License 2.0 | 5 votes |
/** * Acknowledges up to 10 messages via calling * <code>deleteMessageBatch</code>. */ @Override public void action(String queueUrl, List<String> receiptHandles) throws JMSException { if (receiptHandles == null || receiptHandles.isEmpty()) { return; } List<DeleteMessageBatchRequestEntry> deleteMessageBatchRequestEntries = new ArrayList<DeleteMessageBatchRequestEntry>(); int batchId = 0; for (String receiptHandle : receiptHandles) { // Remove the message from queue of unAckMessages unAckMessages.poll(); DeleteMessageBatchRequestEntry entry = new DeleteMessageBatchRequestEntry( Integer.toString(batchId), receiptHandle); deleteMessageBatchRequestEntries.add(entry); batchId++; } DeleteMessageBatchRequest deleteMessageBatchRequest = new DeleteMessageBatchRequest( queueUrl, deleteMessageBatchRequestEntries); /** * TODO: If one of the batch calls fail, then the remaining messages on * the batch will not be deleted, and will be visible and delivered as * duplicate after visibility timeout expires. */ amazonSQSClient.deleteMessageBatch(deleteMessageBatchRequest); }
Example #9
Source File: QueueImpl.java From aws-sdk-java-resources with Apache License 2.0 | 5 votes |
@Override public DeleteMessageBatchResult deleteMessages( List<DeleteMessageBatchRequestEntry> entries, ResultCapture<DeleteMessageBatchResult> extractor) { DeleteMessageBatchRequest request = new DeleteMessageBatchRequest() .withEntries(entries); return deleteMessages(request, extractor); }
Example #10
Source File: QueueImpl.java From aws-sdk-java-resources with Apache License 2.0 | 5 votes |
@Override public DeleteMessageBatchResult deleteMessages( List<DeleteMessageBatchRequestEntry> entries) { return deleteMessages(entries, (ResultCapture<DeleteMessageBatchResult>)null); }
Example #11
Source File: RequestFactoryImpl.java From aws-codecommit-trigger-plugin with Apache License 2.0 | 4 votes |
private DeleteMessageBatchRequestEntry createDeleteMessageBatchRequestEntry(final Message message) { final DeleteMessageBatchRequestEntry entry = new DeleteMessageBatchRequestEntry(); entry.setReceiptHandle(message.getReceiptHandle()); entry.setId(message.getMessageId()); return entry; }
Example #12
Source File: SqsConsumerWorkerCallable.java From datacollector with Apache License 2.0 | 4 votes |
private void sendDeleteMessageBatchRequest( String queueUrl, List<DeleteMessageBatchRequestEntry> deleteRequestEntries ) throws InterruptedException { DeleteMessageBatchRequest deleteRequest = new DeleteMessageBatchRequest() .withQueueUrl(queueUrl) .withEntries(deleteRequestEntries); Future<DeleteMessageBatchResult> deleteResultFuture = sqsAsync.deleteMessageBatchAsync(deleteRequest); try { DeleteMessageBatchResult deleteResult = deleteResultFuture.get(); if (deleteResult.getFailed() != null) { deleteResult.getFailed().forEach(failed -> LOG.error( "Failed to delete message ID {} from queue {} with code {}, sender fault {}", failed.getId(), queueUrl, failed.getCode(), failed.getSenderFault() )); } if (LOG.isDebugEnabled()) { if (deleteResult.getSuccessful() != null) { deleteResult.getSuccessful().forEach(success -> LOG.debug( "Successfully deleted message ID {} from queue {}", success.getId(), queueUrl )); } } } catch (ExecutionException e) { String messageIds = getPendingDeleteMessageIds(queueUrl); LOG.error( Errors.SQS_08.getMessage(), messageIds, queueUrl, e.getMessage(), e ); throw new StageException( Errors.SQS_08, messageIds, queueUrl, e.getMessage(), e ); } }
Example #13
Source File: SqsConsumerWorkerCallable.java From datacollector with Apache License 2.0 | 4 votes |
private void batchFlushHelper(boolean startNew) throws StageException { if (batchContext != null) { context.processBatch(batchContext); if (!context.isPreview() && commitQueueUrlsToMessages.size() > 0) { for (String queueUrl : commitQueueUrlsToMessages.keySet()) { try { List<DeleteMessageBatchRequestEntry> deleteRequestEntries = new LinkedList<>(); for (Message message : commitQueueUrlsToMessages.get(queueUrl)) { deleteRequestEntries.add(new DeleteMessageBatchRequestEntry() .withReceiptHandle(message.getReceiptHandle()) .withId(message.getMessageId()) ); if (deleteRequestEntries.size() >= numMessagesPerRequest) { sendDeleteMessageBatchRequest(queueUrl, deleteRequestEntries); deleteRequestEntries.clear(); } } if (!deleteRequestEntries.isEmpty()) { sendDeleteMessageBatchRequest(queueUrl, deleteRequestEntries); } } catch (InterruptedException e) { LOG.error( "InterruptedException trying to delete SQS messages with IDs {} in queue {}: {}", getPendingDeleteMessageIds(queueUrl), queueUrl, e.getMessage(), e ); Thread.currentThread().interrupt(); break; } } } commitQueueUrlsToMessages.clear(); } batchRecordCount = 0; if (startNew) { batchContext = context.startBatch(); lastBatchStartTimestamp = Clock.systemUTC().millis(); } }
Example #14
Source File: SQSSpanProcessor.java From zipkin-aws with Apache License 2.0 | 4 votes |
private DeleteMessageBatchResult delete(List<DeleteMessageBatchRequestEntry> entries) { return client.deleteMessageBatch(queueUrl, entries); }
Example #15
Source File: AmazonSQSExtendedClient.java From amazon-sqs-java-extended-client-lib with Apache License 2.0 | 3 votes |
/** * <p> * 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); }
Example #16
Source File: AmazonSQSExtendedClient.java From amazon-sqs-java-extended-client-lib with Apache License 2.0 | 2 votes |
/** * <p> * 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 queueUrl * The URL of the Amazon SQS queue to take action on. * @param entries * A list of receipt handles for the messages to be deleted. * * @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(String queueUrl, List<DeleteMessageBatchRequestEntry> entries) { DeleteMessageBatchRequest deleteMessageBatchRequest = new DeleteMessageBatchRequest(queueUrl, entries); return deleteMessageBatch(deleteMessageBatchRequest); }
Example #17
Source File: Queue.java From aws-sdk-java-resources with Apache License 2.0 | 2 votes |
/** * The convenient method form for the <code>DeleteMessages</code> action. * * @see #deleteMessages(DeleteMessageBatchRequest) */ DeleteMessageBatchResult deleteMessages(List<DeleteMessageBatchRequestEntry> entries);
Example #18
Source File: Queue.java From aws-sdk-java-resources with Apache License 2.0 | 2 votes |
/** * The convenient method form for the <code>DeleteMessages</code> action. * * @see #deleteMessages(DeleteMessageBatchRequest, ResultCapture) */ DeleteMessageBatchResult deleteMessages(List<DeleteMessageBatchRequestEntry> entries, ResultCapture<DeleteMessageBatchResult> extractor);
Example #19
Source File: AmazonSQSExtendedClientBase.java From amazon-sqs-java-extended-client-lib with Apache License 2.0 | 2 votes |
/** * <p> * 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. * </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 queueUrl * The URL of the Amazon SQS queue to take action on. * @param entries * A list of receipt handles for the messages to be deleted. * * @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(String queueUrl, List<DeleteMessageBatchRequestEntry> entries) throws AmazonServiceException, AmazonClientException { return amazonSqsToBeExtended.deleteMessageBatch(queueUrl, entries); }