use of com.amazonaws.services.sqs.model.DeleteMessageBatchResult in project conductor by Netflix.
the class SQSObservableQueue method delete.
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;
}
use of com.amazonaws.services.sqs.model.DeleteMessageBatchResult in project beam by apache.
the class SqsUnboundedReader method deleteBatch.
/**
* delete the provided {@code messageIds} from SQS, blocking until all of the messages are
* deleted.
*
* <p>CAUTION: May be invoked from a separate thread.
*
* <p>CAUTION: Retains {@code messageIds}.
*/
private void deleteBatch(List<String> messageIds) throws IOException {
int retries = 0;
List<String> errorMessages = new ArrayList<>();
Map<String, String> pendingReceipts = IntStream.range(0, messageIds.size()).boxed().filter(i -> inFlight.containsKey(messageIds.get(i))).collect(toMap(Object::toString, i -> inFlight.get(messageIds.get(i)).receiptHandle));
while (!pendingReceipts.isEmpty()) {
if (retries >= BATCH_OPERATION_MAX_RETIRES) {
throw new IOException("Failed to delete " + pendingReceipts.size() + " messages after " + retries + " retries: " + String.join(", ", errorMessages));
}
List<DeleteMessageBatchRequestEntry> entries = pendingReceipts.entrySet().stream().map(r -> new DeleteMessageBatchRequestEntry(r.getKey(), r.getValue())).collect(Collectors.toList());
DeleteMessageBatchResult result = sqsClient.deleteMessageBatch(source.getRead().queueUrl(), entries);
// Retry errors except invalid handles
Set<BatchResultErrorEntry> retryErrors = result.getFailed().stream().filter(e -> !e.getCode().equals("ReceiptHandleIsInvalid")).collect(Collectors.toSet());
pendingReceipts.keySet().retainAll(retryErrors.stream().map(BatchResultErrorEntry::getId).collect(Collectors.toSet()));
errorMessages = retryErrors.stream().map(BatchResultErrorEntry::getMessage).collect(Collectors.toList());
retries += 1;
}
deletedIds.add(messageIds);
}
use of com.amazonaws.services.sqs.model.DeleteMessageBatchResult in project hudi by apache.
the class CloudObjectsSelector method deleteBatchOfMessages.
/**
* Delete batch of messages from queue.
*/
protected void deleteBatchOfMessages(AmazonSQS sqs, String queueUrl, List<Message> messagesToBeDeleted) {
DeleteMessageBatchRequest deleteBatchReq = new DeleteMessageBatchRequest().withQueueUrl(queueUrl);
List<DeleteMessageBatchRequestEntry> deleteEntries = deleteBatchReq.getEntries();
for (Message message : messagesToBeDeleted) {
deleteEntries.add(new DeleteMessageBatchRequestEntry().withId(message.getMessageId()).withReceiptHandle(message.getReceiptHandle()));
}
DeleteMessageBatchResult deleteResult = sqs.deleteMessageBatch(deleteBatchReq);
List<String> deleteFailures = deleteResult.getFailed().stream().map(BatchResultErrorEntry::getId).collect(Collectors.toList());
if (!deleteFailures.isEmpty()) {
log.warn("Failed to delete " + deleteFailures.size() + " messages out of " + deleteEntries.size() + " from queue.");
} else {
log.info("Successfully deleted " + deleteEntries.size() + " messages from queue.");
}
}
Aggregations