use of com.amazonaws.services.sqs.model.ChangeMessageVisibilityBatchResult 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);
}
Aggregations