software.amazon.awssdk.services.sqs.model.SendMessageBatchRequestEntry Java Examples
The following examples show how to use
software.amazon.awssdk.services.sqs.model.SendMessageBatchRequestEntry.
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: MessageAttributesIntegrationTest.java From aws-sdk-java-v2 with Apache License 2.0 | 6 votes |
@Test public void sendMessageBatch_WithMessageAttributes_ResultHasMd5OfMessageAttributes() { SendMessageBatchResponse sendMessageBatchResult = sqsAsync.sendMessageBatch(SendMessageBatchRequest.builder() .queueUrl(queueUrl) .entries( SendMessageBatchRequestEntry.builder().id("1").messageBody(MESSAGE_BODY) .messageAttributes(createRandomAttributeValues(1)).build(), SendMessageBatchRequestEntry.builder().id("2").messageBody(MESSAGE_BODY) .messageAttributes(createRandomAttributeValues(2)).build(), SendMessageBatchRequestEntry.builder().id("3").messageBody(MESSAGE_BODY) .messageAttributes(createRandomAttributeValues(3)).build(), SendMessageBatchRequestEntry.builder().id("4").messageBody(MESSAGE_BODY) .messageAttributes(createRandomAttributeValues(4)).build(), SendMessageBatchRequestEntry.builder().id("5").messageBody(MESSAGE_BODY) .messageAttributes(createRandomAttributeValues(5)).build()) .build()) .join(); assertThat(sendMessageBatchResult.successful().size(), greaterThan(0)); assertNotEmpty(sendMessageBatchResult.successful().get(0).id()); assertNotEmpty(sendMessageBatchResult.successful().get(0).md5OfMessageBody()); assertNotEmpty(sendMessageBatchResult.successful().get(0).md5OfMessageAttributes()); }
Example #2
Source File: MessageMD5ChecksumInterceptorTest.java From aws-sdk-java-v2 with Apache License 2.0 | 6 votes |
@Test public void sendMessageBatchPassesValidChecksums() { SendMessageBatchRequestEntry requestEntry = SendMessageBatchRequestEntry.builder() .messageBody(messageBody()) .messageAttributes(messageAttributes()) .build(); SendMessageBatchResultEntry resultEntry = SendMessageBatchResultEntry.builder() .md5OfMessageBody(messageBodyChecksum()) .md5OfMessageAttributes(messageAttributesChecksum()) .build(); SendMessageBatchRequest request = SendMessageBatchRequest.builder() .entries(requestEntry, requestEntry) .build(); SendMessageBatchResponse response = SendMessageBatchResponse.builder() .successful(resultEntry, resultEntry) .build(); assertSuccess(request, response); }
Example #3
Source File: MessageMD5ChecksumInterceptorTest.java From aws-sdk-java-v2 with Apache License 2.0 | 5 votes |
@Test public void sendMessageBatchFailsInvalidBodyChecksums() { SendMessageBatchRequestEntry requestEntry = SendMessageBatchRequestEntry.builder() .messageBody(messageBody()) .messageAttributes(messageAttributes()) .build(); SendMessageBatchResultEntry resultEntry = SendMessageBatchResultEntry.builder() .md5OfMessageBody(messageBodyChecksum()) .md5OfMessageAttributes(messageAttributesChecksum()) .build(); SendMessageBatchResultEntry badResultEntry = SendMessageBatchResultEntry.builder() .md5OfMessageBody("bad") .md5OfMessageAttributes(messageAttributesChecksum()) .build(); SendMessageBatchRequest request = SendMessageBatchRequest.builder() .entries(requestEntry, requestEntry) .build(); SendMessageBatchResponse response = SendMessageBatchResponse.builder() .successful(resultEntry, badResultEntry) .build(); assertFailure(request, response); }
Example #4
Source File: MessageMD5ChecksumInterceptorTest.java From aws-sdk-java-v2 with Apache License 2.0 | 5 votes |
@Test public void sendMessageBatchFailsInvalidAttributeChecksums() { SendMessageBatchRequestEntry requestEntry = SendMessageBatchRequestEntry.builder() .messageBody(messageBody()) .messageAttributes(messageAttributes()) .build(); SendMessageBatchResultEntry resultEntry = SendMessageBatchResultEntry.builder() .md5OfMessageBody(messageBodyChecksum()) .md5OfMessageAttributes(messageAttributesChecksum()) .build(); SendMessageBatchResultEntry badResultEntry = SendMessageBatchResultEntry.builder() .md5OfMessageBody(messageBodyChecksum()) .md5OfMessageAttributes("bad") .build(); SendMessageBatchRequest request = SendMessageBatchRequest.builder() .entries(requestEntry, requestEntry) .build(); SendMessageBatchResponse response = SendMessageBatchResponse.builder() .successful(resultEntry, badResultEntry) .build(); assertFailure(request, response); }
Example #5
Source File: SQSExample.java From aws-doc-sdk-examples with Apache License 2.0 | 5 votes |
public static void sendBatchMessages(SqsClient sqsClient, String queueUrl) { System.out.println("\nSend multiple messages"); // snippet-start:[sqs.java2.sqs_example.send__multiple_messages] SendMessageBatchRequest sendMessageBatchRequest = SendMessageBatchRequest.builder() .queueUrl(queueUrl) .entries(SendMessageBatchRequestEntry.builder().id("id1").messageBody("Hello from msg 1").build(), SendMessageBatchRequestEntry.builder().id("id2").messageBody("msg 2").delaySeconds(10).build()) .build(); sqsClient.sendMessageBatch(sendMessageBatchRequest); // snippet-end:[sqs.java2.sqs_example.send__multiple_messages] }
Example #6
Source File: AWSQueueUtils.java From para with Apache License 2.0 | 5 votes |
/** * Pushes a number of messages in batch to an SQS queue. * @param queueURL the URL of the SQS queue * @param messages the massage bodies */ protected static void pushMessages(String queueURL, List<String> messages) { if (!StringUtils.isBlank(queueURL) && messages != null) { // only allow strings - ie JSON try { int j = 0; List<SendMessageBatchRequestEntry> msgs = new ArrayList<>(MAX_MESSAGES); for (int i = 0; i < messages.size(); i++) { String message = messages.get(i); if (!StringUtils.isBlank(message)) { msgs.add(SendMessageBatchRequestEntry.builder(). messageBody(message). id(Integer.toString(i)).build()); } if (++j >= MAX_MESSAGES || i == messages.size() - 1) { if (!msgs.isEmpty()) { getClient().sendMessageBatch(b -> b.queueUrl(queueURL).entries(msgs)); msgs.clear(); } j = 0; } } } catch (AwsServiceException ase) { logException(ase); } catch (SdkException ace) { logger.error("Could not reach SQS. {}", ace.toString()); } } }
Example #7
Source File: SendReceiveMessages.java From aws-doc-sdk-examples with Apache License 2.0 | 4 votes |
public static void main(String[] args) { SqsClient sqsClient = SqsClient.builder() .region(Region.US_WEST_2) .build(); try { CreateQueueRequest request = CreateQueueRequest.builder() .queueName(QUEUE_NAME) .build(); CreateQueueResponse createResult = sqsClient.createQueue(request); GetQueueUrlRequest getQueueRequest = GetQueueUrlRequest.builder() .queueName(QUEUE_NAME) .build(); String queueUrl = sqsClient.getQueueUrl(getQueueRequest).queueUrl(); SendMessageRequest sendMsgRequest = SendMessageRequest.builder() .queueUrl(queueUrl) .messageBody("hello world") .delaySeconds(5) .build(); sqsClient.sendMessage(sendMsgRequest); // Send multiple messages to the queue SendMessageBatchRequest sendBatchRequest = SendMessageBatchRequest.builder() .queueUrl(queueUrl) .entries( SendMessageBatchRequestEntry.builder() .messageBody("Hello from message 1") .id("msg_1") .build() , SendMessageBatchRequestEntry.builder() .messageBody("Hello from message 2") .delaySeconds(10) .id("msg_2") .build()) .build(); sqsClient.sendMessageBatch(sendBatchRequest); // Receive messages from the queue ReceiveMessageRequest receiveRequest = ReceiveMessageRequest.builder() .queueUrl(queueUrl) .build(); List<Message> messages = sqsClient.receiveMessage(receiveRequest).messages(); // Print out the messages for (Message m : messages) { System.out.println("\n" +m.body()); } } catch (QueueNameExistsException e) { throw e; } }