Search in sources :

Example 1 with ReceiveMessageResponse

use of software.amazon.awssdk.services.sqs.model.ReceiveMessageResponse in project beam by apache.

the class SqsUnboundedReader method pull.

/**
 * BLOCKING. Fetch another batch of messages from SQS.
 */
private void pull() {
    if (inFlight.size() >= MAX_IN_FLIGHT) {
        // messages faster than we can checkpoint them.
        return;
    }
    long requestTimeMsSinceEpoch = now();
    long deadlineMsSinceEpoch = requestTimeMsSinceEpoch + visibilityTimeoutMs;
    final ReceiveMessageRequest receiveMessageRequest = ReceiveMessageRequest.builder().maxNumberOfMessages(MAX_NUMBER_OF_MESSAGES).attributeNamesWithStrings(SENT_TIMESTAMP.toString()).queueUrl(queueUrl()).build();
    final ReceiveMessageResponse receiveMessageResponse = sqsClient.receiveMessage(receiveMessageRequest);
    final List<Message> messages = receiveMessageResponse.messages();
    if (messages == null || messages.isEmpty()) {
        return;
    }
    lastReceivedMsSinceEpoch = requestTimeMsSinceEpoch;
    // Capture the received messages.
    for (Message orgMsg : messages) {
        long msgTimeStamp = Long.parseLong(orgMsg.attributes().get(SENT_TIMESTAMP));
        SqsMessage message = SqsMessage.create(orgMsg.body(), orgMsg.messageId(), orgMsg.receiptHandle(), msgTimeStamp, requestTimeMsSinceEpoch);
        messagesNotYetRead.add(message);
        notYetReadBytes += message.getBody().getBytes(UTF_8).length;
        inFlight.put(message.getMessageId(), new InFlightState(message.getReceiptHandle(), requestTimeMsSinceEpoch, deadlineMsSinceEpoch));
        numReceived++;
        numReceivedRecently.add(requestTimeMsSinceEpoch, 1L);
        minReceivedTimestampMsSinceEpoch.add(requestTimeMsSinceEpoch, msgTimeStamp);
        maxReceivedTimestampMsSinceEpoch.add(requestTimeMsSinceEpoch, msgTimeStamp);
        minUnreadTimestampMsSinceEpoch.add(requestTimeMsSinceEpoch, msgTimeStamp);
    }
}
Also used : ReceiveMessageRequest(software.amazon.awssdk.services.sqs.model.ReceiveMessageRequest) Message(software.amazon.awssdk.services.sqs.model.Message) ReceiveMessageResponse(software.amazon.awssdk.services.sqs.model.ReceiveMessageResponse)

Aggregations

Message (software.amazon.awssdk.services.sqs.model.Message)1 ReceiveMessageRequest (software.amazon.awssdk.services.sqs.model.ReceiveMessageRequest)1 ReceiveMessageResponse (software.amazon.awssdk.services.sqs.model.ReceiveMessageResponse)1