software.amazon.awssdk.services.sqs.model.ReceiveMessageResponse Java Examples
The following examples show how to use
software.amazon.awssdk.services.sqs.model.ReceiveMessageResponse.
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: MessageMD5ChecksumInterceptor.java From aws-sdk-java-v2 with Apache License 2.0 | 6 votes |
@Override public void afterExecution(Context.AfterExecution context, ExecutionAttributes executionAttributes) { SdkResponse response = context.response(); SdkRequest originalRequest = context.request(); if (response != null) { if (originalRequest instanceof SendMessageRequest) { SendMessageRequest sendMessageRequest = (SendMessageRequest) originalRequest; SendMessageResponse sendMessageResult = (SendMessageResponse) response; sendMessageOperationMd5Check(sendMessageRequest, sendMessageResult); } else if (originalRequest instanceof ReceiveMessageRequest) { ReceiveMessageResponse receiveMessageResult = (ReceiveMessageResponse) response; receiveMessageResultMd5Check(receiveMessageResult); } else if (originalRequest instanceof SendMessageBatchRequest) { SendMessageBatchRequest sendMessageBatchRequest = (SendMessageBatchRequest) originalRequest; SendMessageBatchResponse sendMessageBatchResult = (SendMessageBatchResponse) response; sendMessageBatchOperationMd5Check(sendMessageBatchRequest, sendMessageBatchResult); } } }
Example #2
Source File: MessageMD5ChecksumInterceptorTest.java From aws-sdk-java-v2 with Apache License 2.0 | 6 votes |
@Test public void receiveMessageFailsInvalidBodyChecksum() { Message message = Message.builder() .body(messageBody()) .messageAttributes(messageAttributes()) .md5OfBody(messageBodyChecksum()) .md5OfMessageAttributes(messageAttributesChecksum()) .build(); Message badMessage = Message.builder() .body(messageBody()) .messageAttributes(messageAttributes()) .md5OfBody("bad") .md5OfMessageAttributes(messageAttributesChecksum()) .build(); ReceiveMessageResponse response = ReceiveMessageResponse.builder() .messages(message, badMessage) .build(); assertFailure(ReceiveMessageRequest.builder().build(), response); }
Example #3
Source File: MessageMD5ChecksumInterceptorTest.java From aws-sdk-java-v2 with Apache License 2.0 | 6 votes |
@Test public void receiveMessageFailsInvalidAttributeChecksum() { Message message = Message.builder() .body(messageBody()) .messageAttributes(messageAttributes()) .md5OfBody(messageBodyChecksum()) .md5OfMessageAttributes(messageAttributesChecksum()) .build(); Message badMessage = Message.builder() .body(messageBody()) .messageAttributes(messageAttributes()) .md5OfBody(messageBodyChecksum()) .md5OfMessageAttributes("bad") .build(); ReceiveMessageResponse response = ReceiveMessageResponse.builder() .messages(message, badMessage) .build(); assertFailure(ReceiveMessageRequest.builder().build(), response); }
Example #4
Source File: SqsMessageQueueReceiverEndpointIntegrationTest.java From synapse with Apache License 2.0 | 6 votes |
@Test public void shouldRetryAfterTimeout() throws ExecutionException, InterruptedException { //given queue returns error on first request, ok on second request returnError = ImmutableList.of(true, false); final String expectedPayload = "some payload: " + LocalDateTime.now(); sqsSender.send(message("test-key-shouldSendAndReceiveSqsMessage", expectedPayload)).join(); //when queue returns error in first request receiveMessageRequest = buildReceiveMessageRequest(); CompletableFuture<ReceiveMessageResponse> receiveMessageResponseCompletableFuture = delegateAsyncClient.receiveMessage(receiveMessageRequest); await() .atMost(5, SECONDS) .until(receiveMessageResponseCompletableFuture::isDone); //then String returnedMessage = receiveMessageResponseCompletableFuture.get().messages().get(0).body(); assertThat(returnedMessage, is(expectedPayload)); assertThat(StubController.getCount(), is(2)); }
Example #5
Source File: SqsUnboundedReader.java From beam with Apache License 2.0 | 6 votes |
private void pull() { final ReceiveMessageRequest receiveMessageRequest = ReceiveMessageRequest.builder() .maxNumberOfMessages(MAX_NUMBER_OF_MESSAGES) .attributeNamesWithStrings( MessageSystemAttributeName.APPROXIMATE_FIRST_RECEIVE_TIMESTAMP.toString()) .queueUrl(source.getRead().queueUrl()) .build(); final ReceiveMessageResponse receiveMessageResponse = source.getSqs().receiveMessage(receiveMessageRequest); final List<Message> messages = receiveMessageResponse.messages(); if (messages == null || messages.isEmpty()) { return; } messagesNotYetRead.addAll(messages); }
Example #6
Source File: QuarksShieldAsyncResource.java From quarkus-quickstarts with Apache License 2.0 | 5 votes |
@GET @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) public Uni<List<Quark>> receive() { return Uni.createFrom() .completionStage(sqs.receiveMessage(m -> m.maxNumberOfMessages(10).queueUrl(queueUrl))) .onItem().apply(ReceiveMessageResponse::messages) .onItem().apply(m -> m.stream().map(Message::body).map(this::toQuark).collect(Collectors.toList())); }
Example #7
Source File: MessageMD5ChecksumInterceptor.java From aws-sdk-java-v2 with Apache License 2.0 | 5 votes |
/** * Throw an exception if the MD5 checksums included in the ReceiveMessageResponse do not match the * client-side calculation on the received messages. */ private static void receiveMessageResultMd5Check(ReceiveMessageResponse receiveMessageResult) { if (receiveMessageResult.messages() != null) { for (Message messageReceived : receiveMessageResult.messages()) { String messageBody = messageReceived.body(); String bodyMd5Returned = messageReceived.md5OfBody(); String clientSideBodyMd5 = calculateMessageBodyMd5(messageBody); if (!clientSideBodyMd5.equals(bodyMd5Returned)) { throw SdkClientException.builder() .message(String.format(MD5_MISMATCH_ERROR_MESSAGE, MESSAGE_BODY, clientSideBodyMd5, bodyMd5Returned)) .build(); } Map<String, MessageAttributeValue> messageAttr = messageReceived.messageAttributes(); if (messageAttr != null && !messageAttr.isEmpty()) { String attrMd5Returned = messageReceived.md5OfMessageAttributes(); String clientSideAttrMd5 = calculateMessageAttributesMd5(messageAttr); if (!clientSideAttrMd5.equals(attrMd5Returned)) { throw SdkClientException.builder() .message(String.format(MD5_MISMATCH_ERROR_MESSAGE, MESSAGE_ATTRIBUTES, clientSideAttrMd5, attrMd5Returned)) .build(); } } } } }
Example #8
Source File: MessageAttributesIntegrationTest.java From aws-sdk-java-v2 with Apache License 2.0 | 5 votes |
@Test public void receiveMessage_WithAllAttributesRequested_ReturnsAttributes() throws Exception { sendTestMessage(); ReceiveMessageRequest receiveMessageRequest = ReceiveMessageRequest.builder().queueUrl(queueUrl).waitTimeSeconds(5) .visibilityTimeout(0).messageAttributeNames("All").build(); ReceiveMessageResponse receiveMessageResult = sqsAsync.receiveMessage(receiveMessageRequest).join(); assertFalse(receiveMessageResult.messages().isEmpty()); Message message = receiveMessageResult.messages().get(0); assertEquals(MESSAGE_BODY, message.body()); assertNotEmpty(message.md5OfBody()); assertNotEmpty(message.md5OfMessageAttributes()); }
Example #9
Source File: MessageAttributesIntegrationTest.java From aws-sdk-java-v2 with Apache License 2.0 | 5 votes |
/** * Tests SQS operations that involve message attributes checksum. */ @Test public void receiveMessage_WithNoAttributesRequested_DoesNotReturnAttributes() throws Exception { sendTestMessage(); ReceiveMessageRequest receiveMessageRequest = ReceiveMessageRequest.builder().queueUrl(queueUrl).waitTimeSeconds(5) .visibilityTimeout(0).build(); ReceiveMessageResponse receiveMessageResult = sqsAsync.receiveMessage(receiveMessageRequest).join(); assertFalse(receiveMessageResult.messages().isEmpty()); Message message = receiveMessageResult.messages().get(0); assertEquals(MESSAGE_BODY, message.body()); assertNotEmpty(message.md5OfBody()); assertNull(message.md5OfMessageAttributes()); }
Example #10
Source File: MessageMD5ChecksumInterceptorTest.java From aws-sdk-java-v2 with Apache License 2.0 | 5 votes |
@Test public void receiveMessagePassesValidChecksums() { Message message = Message.builder() .body(messageBody()) .messageAttributes(messageAttributes()) .md5OfBody(messageBodyChecksum()) .md5OfMessageAttributes(messageAttributesChecksum()) .build(); ReceiveMessageResponse response = ReceiveMessageResponse.builder() .messages(message, message) .build(); assertSuccess(ReceiveMessageRequest.builder().build(), response); }
Example #11
Source File: SqsMessageQueueReceiverEndpointIntegrationTest.java From synapse with Apache License 2.0 | 5 votes |
@RequestMapping(value = "/**", produces = {"text/xml"}) @ResponseBody public ResponseEntity<?> getResponse() throws InterruptedException, ExecutionException { if (returnError.get(count.getAndIncrement())) { return new ResponseEntity<Void>(HttpStatus.BAD_GATEWAY); } ReceiveMessageResponse receiveMessageResponse = asyncClient.receiveMessage(receiveMessageRequest).get(); return ResponseEntity.ok(mockedXmlResponse(receiveMessageResponse.messages().get(0))); }
Example #12
Source File: SqsIOTest.java From beam with Apache License 2.0 | 5 votes |
@Test public void testWrite() { final SqsClient client = EmbeddedSqsServer.getClient(); final String queueUrl = EmbeddedSqsServer.getQueueUrl(); List<SendMessageRequest> messages = new ArrayList<>(); for (int i = 0; i < 100; i++) { final SendMessageRequest request = SendMessageRequest.builder() .queueUrl(queueUrl) .messageBody("This is a test " + i) .build(); messages.add(request); } pipeline .apply(Create.of(messages)) .apply(SqsIO.write().withSqsClientProvider(SqsClientProviderMock.of(client))); pipeline.run().waitUntilFinish(); List<String> received = new ArrayList<>(); while (received.size() < 100) { ReceiveMessageRequest receiveMessageRequest = ReceiveMessageRequest.builder().queueUrl(queueUrl).build(); final ReceiveMessageResponse receiveMessageResponse = client.receiveMessage(receiveMessageRequest); if (receiveMessageResponse != null) { for (Message message : receiveMessageResponse.messages()) { received.add(message.body()); } } } assertEquals(100, received.size()); for (int i = 0; i < 100; i++) { received.contains("This is a test " + i); } }