use of com.amazonaws.services.sqs.model.BatchResultErrorEntry in project beam by apache.
the class SqsUnboundedReader method extendBatch.
/**
* BLOCKING Extend the visibility timeout for messages from SQS with the given {@code
* receiptHandles}.
*/
void extendBatch(long nowMsSinceEpoch, List<String> receiptHandles, int extensionSec) throws IOException {
int retries = 0;
int numMessages = receiptHandles.size();
Map<String, String> pendingReceipts = IntStream.range(0, receiptHandles.size()).boxed().collect(toMap(Object::toString, receiptHandles::get));
List<String> errorMessages = new ArrayList<>();
while (!pendingReceipts.isEmpty()) {
if (retries >= BATCH_OPERATION_MAX_RETIRES) {
throw new IOException("Failed to extend visibility timeout for " + pendingReceipts.size() + " messages after " + retries + " retries: " + String.join(", ", errorMessages));
}
List<ChangeMessageVisibilityBatchRequestEntry> entries = pendingReceipts.entrySet().stream().map(r -> new ChangeMessageVisibilityBatchRequestEntry(r.getKey(), r.getValue()).withVisibilityTimeout(extensionSec)).collect(Collectors.toList());
ChangeMessageVisibilityBatchResult result = sqsClient.changeMessageVisibilityBatch(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;
}
numExtendedDeadlines.add(nowMsSinceEpoch, numMessages);
}
use of com.amazonaws.services.sqs.model.BatchResultErrorEntry 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);
}
Aggregations