com.amazonaws.services.sqs.model.SendMessageRequest Java Examples
The following examples show how to use
com.amazonaws.services.sqs.model.SendMessageRequest.
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: QueueMessagingTemplateTest.java From spring-cloud-aws with Apache License 2.0 | 7 votes |
@Test void send_withCustomDestinationResolveAndDestination_usesDestination() { AmazonSQSAsync amazonSqs = createAmazonSqs(); QueueMessagingTemplate queueMessagingTemplate = new QueueMessagingTemplate( amazonSqs, (DestinationResolver<String>) name -> name.toUpperCase(Locale.ENGLISH), null); Message<String> stringMessage = MessageBuilder.withPayload("message content") .build(); queueMessagingTemplate.send("myqueue", stringMessage); ArgumentCaptor<SendMessageRequest> sendMessageRequestArgumentCaptor = ArgumentCaptor .forClass(SendMessageRequest.class); verify(amazonSqs).sendMessage(sendMessageRequestArgumentCaptor.capture()); assertThat(sendMessageRequestArgumentCaptor.getValue().getQueueUrl()) .isEqualTo("MYQUEUE"); }
Example #2
Source File: AmazonSQSResponderClient.java From amazon-sqs-java-temporary-queues-client with Apache License 2.0 | 7 votes |
@Override public void sendResponseMessage(MessageContent request, MessageContent response) { MessageAttributeValue attribute = request.getMessageAttributes().get(AmazonSQSRequesterClient.RESPONSE_QUEUE_URL_ATTRIBUTE_NAME); if (attribute != null) { String replyQueueUrl = attribute.getStringValue(); try { SendMessageRequest responseRequest = response.toSendMessageRequest() .withQueueUrl(replyQueueUrl); sqs.sendMessage(responseRequest); } catch (QueueDoesNotExistException e) { // Stale request, ignore // TODO-RS: CW metric LOG.warn("Ignoring response to deleted response queue: " + replyQueueUrl); } } else { // TODO-RS: CW metric LOG.warn("Attempted to send response when none was requested"); } }
Example #3
Source File: QueueMessageChannelTest.java From spring-cloud-aws with Apache License 2.0 | 7 votes |
@Test @SuppressWarnings("unchecked") void sendMessage_withExecutionExceptionWhileSendingAsyncMessage_throwMessageDeliveryException() throws Exception { // Arrange Future<SendMessageResult> future = mock(Future.class); when(future.get(1000, TimeUnit.MILLISECONDS)) .thenThrow(new ExecutionException(new Exception())); AmazonSQSAsync amazonSqs = mock(AmazonSQSAsync.class); when(amazonSqs.sendMessageAsync(any(SendMessageRequest.class))) .thenReturn(future); QueueMessageChannel queueMessageChannel = new QueueMessageChannel(amazonSqs, "http://testQueue"); // Assert assertThatThrownBy(() -> queueMessageChannel .send(MessageBuilder.withPayload("Hello").build(), 1000)) .isInstanceOf(MessageDeliveryException.class); }
Example #4
Source File: AmazonSQSRequesterClientTest.java From amazon-sqs-java-temporary-queues-client with Apache License 2.0 | 7 votes |
@Test public void happyPath() throws TimeoutException, InterruptedException, ExecutionException { String requestMessageBody = "Ping"; String responseMessageBody = "Pong"; String queueUrl = sqs.createQueue("MyQueue").getQueueUrl(); SendMessageRequest request = new SendMessageRequest() .withQueueUrl(queueUrl) .withMessageBody(requestMessageBody); Future<Message> future = requesterClient.sendMessageAndGetResponseAsync(request, 5, TimeUnit.SECONDS); Message requestMessage = sqs.receiveMessage(queueUrl).getMessages().get(0); assertEquals(requestMessageBody, requestMessage.getBody()); String responseQueueUrl = requestMessage.getMessageAttributes().get(AmazonSQSRequesterClient.RESPONSE_QUEUE_URL_ATTRIBUTE_NAME).getStringValue(); assertNotNull(responseQueueUrl); responderClient.sendResponseMessage(MessageContent.fromMessage(requestMessage), new MessageContent(responseMessageBody)); Message response = future.get(5, TimeUnit.SECONDS); assertEquals(responseMessageBody, response.getBody()); // Make sure the response queue gets deleted SQSQueueUtils.awaitQueueDeleted(sqs, responseQueueUrl, 70, TimeUnit.SECONDS); }
Example #5
Source File: SqsExecutor.java From spring-integration-aws with MIT License | 6 votes |
/** * Executes the outbound Sqs Operation. * */ public Object executeOutboundOperation(final Message<?> message) { try { String serializedMessage = messageMarshaller.serialize(message); if (queue == null) { SendMessageRequest request = new SendMessageRequest(queueUrl, serializedMessage); SendMessageResult result = sqsClient.sendMessage(request); log.debug("Message sent, Id:" + result.getMessageId()); } else { queue.add(serializedMessage); } } catch (MessageMarshallerException e) { log.error(e.getMessage(), e); throw new MessagingException(e.getMessage(), e.getCause()); } return message.getPayload(); }
Example #6
Source File: QueueMessageChannelTest.java From spring-cloud-aws with Apache License 2.0 | 6 votes |
@Test void sendMessage_withDelayHeader_shouldSetDelayOnSendMessageRequestAndNotSetItAsHeaderAsMessageAttribute() throws Exception { // Arrange AmazonSQSAsync amazonSqs = mock(AmazonSQSAsync.class); ArgumentCaptor<SendMessageRequest> sendMessageRequestArgumentCaptor = ArgumentCaptor .forClass(SendMessageRequest.class); when(amazonSqs.sendMessage(sendMessageRequestArgumentCaptor.capture())) .thenReturn(new SendMessageResult()); QueueMessageChannel queueMessageChannel = new QueueMessageChannel(amazonSqs, "http://testQueue"); Message<String> message = MessageBuilder.withPayload("Hello") .setHeader(SqsMessageHeaders.SQS_DELAY_HEADER, 15).build(); // Act queueMessageChannel.send(message); // Assert SendMessageRequest sendMessageRequest = sendMessageRequestArgumentCaptor .getValue(); assertThat(sendMessageRequest.getDelaySeconds()).isEqualTo(new Integer(15)); assertThat(sendMessageRequest.getMessageAttributes() .containsKey(SqsMessageHeaders.SQS_DELAY_HEADER)).isFalse(); }
Example #7
Source File: QueueMessageChannelTest.java From spring-cloud-aws with Apache License 2.0 | 6 votes |
@Test void sendMessage_withGroupIdHeader_shouldSetGroupIdOnSendMessageRequestAndNotSetItAsHeaderAsMessageAttribute() throws Exception { // Arrange AmazonSQSAsync amazonSqs = mock(AmazonSQSAsync.class); ArgumentCaptor<SendMessageRequest> sendMessageRequestArgumentCaptor = ArgumentCaptor .forClass(SendMessageRequest.class); when(amazonSqs.sendMessage(sendMessageRequestArgumentCaptor.capture())) .thenReturn(new SendMessageResult()); QueueMessageChannel queueMessageChannel = new QueueMessageChannel(amazonSqs, "http://testQueue"); Message<String> message = MessageBuilder.withPayload("Hello") .setHeader(SqsMessageHeaders.SQS_GROUP_ID_HEADER, "id-5").build(); // Act queueMessageChannel.send(message); // Assert SendMessageRequest sendMessageRequest = sendMessageRequestArgumentCaptor .getValue(); assertThat(sendMessageRequest.getMessageGroupId()).isEqualTo("id-5"); assertThat(sendMessageRequest.getMessageAttributes() .containsKey(SqsMessageHeaders.SQS_GROUP_ID_HEADER)).isFalse(); }
Example #8
Source File: AmazonSQSRequesterClient.java From amazon-sqs-java-temporary-queues-client with Apache License 2.0 | 6 votes |
@Override public CompletableFuture<Message> sendMessageAndGetResponseAsync(SendMessageRequest request, int timeout, TimeUnit unit) { String queueName = queuePrefix + UUID.randomUUID().toString(); CreateQueueRequest createQueueRequest = new CreateQueueRequest() .withQueueName(queueName) .withAttributes(queueAttributes); String responseQueueUrl = sqs.createQueue(createQueueRequest).getQueueUrl(); SendMessageRequest requestWithResponseUrl = SQSQueueUtils.copyWithExtraAttributes(request, Collections.singletonMap(RESPONSE_QUEUE_URL_ATTRIBUTE_NAME, new MessageAttributeValue().withDataType("String").withStringValue(responseQueueUrl))); // TODO-RS: Should be using sendMessageAsync sqs.sendMessage(requestWithResponseUrl); CompletableFuture<Message> future = new CompletableFuture<>(); // TODO-RS: accept an AmazonSQSAsync instead and use its threads instead of our own. // TODO-RS: complete the future exceptionally, for the right set of SQS exceptions SQSMessageConsumer consumer = new ResponseListener(responseQueueUrl, future); responseConsumers.add(consumer); consumer.runFor(timeout, unit); return future; }
Example #9
Source File: QueueMessagingTemplateTest.java From spring-cloud-aws with Apache License 2.0 | 6 votes |
@Test void send_withDefaultDestination_usesDefaultDestination() { AmazonSQSAsync amazonSqs = createAmazonSqs(); QueueMessagingTemplate queueMessagingTemplate = new QueueMessagingTemplate( amazonSqs); queueMessagingTemplate.setDefaultDestinationName("my-queue"); Message<String> stringMessage = MessageBuilder.withPayload("message content") .build(); queueMessagingTemplate.send(stringMessage); ArgumentCaptor<SendMessageRequest> sendMessageRequestArgumentCaptor = ArgumentCaptor .forClass(SendMessageRequest.class); verify(amazonSqs).sendMessage(sendMessageRequestArgumentCaptor.capture()); assertThat(sendMessageRequestArgumentCaptor.getValue().getQueueUrl()) .isEqualTo("https://queue-url.com"); }
Example #10
Source File: QueueMessagingTemplateTest.java From spring-cloud-aws with Apache License 2.0 | 6 votes |
@Test void send_withDestination_usesDestination() { AmazonSQSAsync amazonSqs = createAmazonSqs(); QueueMessagingTemplate queueMessagingTemplate = new QueueMessagingTemplate( amazonSqs); Message<String> stringMessage = MessageBuilder.withPayload("message content") .build(); queueMessagingTemplate.send("my-queue", stringMessage); ArgumentCaptor<SendMessageRequest> sendMessageRequestArgumentCaptor = ArgumentCaptor .forClass(SendMessageRequest.class); verify(amazonSqs).sendMessage(sendMessageRequestArgumentCaptor.capture()); assertThat(sendMessageRequestArgumentCaptor.getValue().getQueueUrl()) .isEqualTo("https://queue-url.com"); }
Example #11
Source File: SQSMessageProducerFifoTest.java From amazon-sqs-java-messaging-lib with Apache License 2.0 | 6 votes |
/** * Test sendInternal input with SQSByteMessage */ @Test public void testSendInternalSQSByteMessage() throws JMSException { SQSBytesMessage msg = spy(new SQSBytesMessage()); msg.setStringProperty(SQSMessagingClientConstants.JMSX_GROUP_ID, GROUP_ID); msg.setStringProperty(SQSMessagingClientConstants.JMS_SQS_DEDUPLICATION_ID, DEDUP_ID); msg.writeByte((byte)0); msg.reset(); when(amazonSQSClient.sendMessage(any(SendMessageRequest.class))) .thenReturn(new SendMessageResult().withMessageId(MESSAGE_ID).withSequenceNumber(SEQ_NUMBER)); producer.sendInternal(destination, msg); String messageBody = "AA=="; verify(amazonSQSClient).sendMessage(argThat(new sendMessageRequestMatcher(QUEUE_URL, messageBody, SQSMessage.BYTE_MESSAGE_TYPE, GROUP_ID, DEDUP_ID))); verify(msg).setJMSDestination(destination); verify(msg).setJMSMessageID("ID:" + MESSAGE_ID); verify(msg).setSQSMessageId(MESSAGE_ID); verify(msg).setSequenceNumber(SEQ_NUMBER); }
Example #12
Source File: SQSMessageProducerFifoTest.java From amazon-sqs-java-messaging-lib with Apache License 2.0 | 6 votes |
/** * Test sendInternal input with SQSObjectMessage */ @Test public void testSendInternalSQSObjectMessage() throws JMSException { HashSet<String> set = new HashSet<String>(); set.add("data1"); SQSObjectMessage msg = spy(new SQSObjectMessage(set)); msg.setStringProperty(SQSMessagingClientConstants.JMSX_GROUP_ID, GROUP_ID); msg.setStringProperty(SQSMessagingClientConstants.JMS_SQS_DEDUPLICATION_ID, DEDUP_ID); String msgBody = msg.getMessageBody(); when(amazonSQSClient.sendMessage(any(SendMessageRequest.class))) .thenReturn(new SendMessageResult().withMessageId(MESSAGE_ID).withSequenceNumber(SEQ_NUMBER)); producer.sendInternal(destination, msg); verify(amazonSQSClient).sendMessage(argThat(new sendMessageRequestMatcher(QUEUE_URL, msgBody, SQSMessage.OBJECT_MESSAGE_TYPE, GROUP_ID, DEDUP_ID))); verify(msg).setJMSDestination(destination); verify(msg).setJMSMessageID("ID:" + MESSAGE_ID); verify(msg).setSQSMessageId(MESSAGE_ID); verify(msg).setSequenceNumber(SEQ_NUMBER); }
Example #13
Source File: QueueMessageChannelTest.java From spring-cloud-aws with Apache License 2.0 | 6 votes |
@Test void sendMessage_withoutDelayHeader_shouldNotSetDelayOnSendMessageRequestAndNotSetHeaderAsMessageAttribute() throws Exception { // Arrange AmazonSQSAsync amazonSqs = mock(AmazonSQSAsync.class); ArgumentCaptor<SendMessageRequest> sendMessageRequestArgumentCaptor = ArgumentCaptor .forClass(SendMessageRequest.class); when(amazonSqs.sendMessage(sendMessageRequestArgumentCaptor.capture())) .thenReturn(new SendMessageResult()); QueueMessageChannel queueMessageChannel = new QueueMessageChannel(amazonSqs, "http://testQueue"); Message<String> message = MessageBuilder.withPayload("Hello").build(); // Act queueMessageChannel.send(message); // Assert SendMessageRequest sendMessageRequest = sendMessageRequestArgumentCaptor .getValue(); assertThat(sendMessageRequest.getDelaySeconds()).isNull(); assertThat(sendMessageRequest.getMessageAttributes() .containsKey(SqsMessageHeaders.SQS_DELAY_HEADER)).isFalse(); }
Example #14
Source File: AmazonSQSResponsesClientIT.java From amazon-sqs-java-temporary-queues-client with Apache License 2.0 | 6 votes |
@Test public void test() throws Exception { SQSMessageConsumer consumer = SQSMessageConsumerBuilder.standard() .withAmazonSQS(sqs) .withQueueUrl(requestQueueUrl) .withConsumer(message -> { sqsResponder.sendResponseMessage(MessageContent.fromMessage(message), new MessageContent("Right back atcha buddy!")); }) .build(); consumer.start(); try { SendMessageRequest request = new SendMessageRequest() .withMessageBody("Hi there!") .withQueueUrl(requestQueueUrl); Message replyMessage = sqsRequester.sendMessageAndGetResponse(request, 5, TimeUnit.SECONDS); assertEquals("Right back atcha buddy!", replyMessage.getBody()); } finally { consumer.terminate(); } }
Example #15
Source File: QueueMessageChannelTest.java From spring-cloud-aws with Apache License 2.0 | 6 votes |
@Test @SuppressWarnings("unchecked") void sendMessage_withSendMessageAsyncTakingMoreTimeThanSpecifiedTimeout_returnsFalse() throws Exception { // Arrange Future<SendMessageResult> future = mock(Future.class); when(future.get(1000, TimeUnit.MILLISECONDS)).thenThrow(new TimeoutException()); AmazonSQSAsync amazonSqs = mock(AmazonSQSAsync.class); when(amazonSqs.sendMessageAsync(any(SendMessageRequest.class))) .thenReturn(future); QueueMessageChannel queueMessageChannel = new QueueMessageChannel(amazonSqs, "http://testQueue"); // Act boolean result = queueMessageChannel .send(MessageBuilder.withPayload("Hello").build(), 1000); // Assert assertThat(result).isFalse(); }
Example #16
Source File: QueueMessageChannelTest.java From spring-cloud-aws with Apache License 2.0 | 6 votes |
@Test @SuppressWarnings("unchecked") void sendMessage_withTimeout_sendsMessageAsyncAndReturnsTrueOnceFutureCompleted() throws Exception { // Arrange Future<SendMessageResult> future = mock(Future.class); when(future.get(1000, TimeUnit.MILLISECONDS)).thenReturn(new SendMessageResult()); AmazonSQSAsync amazonSqs = mock(AmazonSQSAsync.class); when(amazonSqs.sendMessageAsync(any(SendMessageRequest.class))) .thenReturn(future); QueueMessageChannel queueMessageChannel = new QueueMessageChannel(amazonSqs, "http://testQueue"); // Act boolean result = queueMessageChannel .send(MessageBuilder.withPayload("Hello").build(), 1000); // Assert assertThat(result).isTrue(); verify(amazonSqs, only()).sendMessageAsync(any(SendMessageRequest.class)); }
Example #17
Source File: QueueMessageChannelTest.java From spring-cloud-aws with Apache License 2.0 | 6 votes |
@Test void sendMessage_withUuidAsId_shouldConvertUuidToString() throws Exception { // Arrange AmazonSQSAsync amazonSqs = mock(AmazonSQSAsync.class); QueueMessageChannel messageChannel = new QueueMessageChannel(amazonSqs, "http://testQueue"); Message<String> message = MessageBuilder.withPayload("Hello").build(); UUID uuid = (UUID) message.getHeaders().get(MessageHeaders.ID); ArgumentCaptor<SendMessageRequest> sendMessageRequestArgumentCaptor = ArgumentCaptor .forClass(SendMessageRequest.class); when(amazonSqs.sendMessage(sendMessageRequestArgumentCaptor.capture())) .thenReturn(new SendMessageResult()); // Act boolean sent = messageChannel.send(message); // Assert assertThat(sent).isTrue(); assertThat(sendMessageRequestArgumentCaptor.getValue().getMessageAttributes() .get(MessageHeaders.ID).getStringValue()).isEqualTo(uuid.toString()); }
Example #18
Source File: SQSQueueUtilsTest.java From amazon-sqs-java-temporary-queues-client with Apache License 2.0 | 6 votes |
/** * This test fails if a new member is added to SendMessageRequest class. * * This acts as a reminder to notify us to update the * {@link SQSQueueUtils#copyWithExtraAttributes(SendMessageRequest, Map)} method when a * member is added to {@link SendMessageRequest}. */ @Test public void sendMessageRequestCopyWithExtraAttributes() throws IllegalAccessException { SendMessageRequest sendMessageRequest = new SendMessageRequest() .withQueueUrl("queueUrl") .withMessageBody("messageBody") .withDelaySeconds(5) .withMessageAttributes(Collections.emptyMap()) .withMessageDeduplicationId("dedup") .withMessageGroupId("groupId"); SendMessageRequest sendMessageRequestCopy = SQSQueueUtils.copyWithExtraAttributes(sendMessageRequest, Collections.emptyMap()); assertNoFieldsAreNull(SendMessageRequest.class, sendMessageRequestCopy); }
Example #19
Source File: SQSMessageProducerFifoTest.java From amazon-sqs-java-messaging-lib with Apache License 2.0 | 6 votes |
/** * Test sendInternal input with SQSTextMessage */ @Test public void testSendInternalSQSTextMessage() throws JMSException { String messageBody = "MyText1"; SQSTextMessage msg = spy(new SQSTextMessage(messageBody)); msg.setStringProperty(SQSMessagingClientConstants.JMSX_GROUP_ID, GROUP_ID); msg.setStringProperty(SQSMessagingClientConstants.JMS_SQS_DEDUPLICATION_ID, DEDUP_ID); when(amazonSQSClient.sendMessage(any(SendMessageRequest.class))) .thenReturn(new SendMessageResult().withMessageId(MESSAGE_ID).withSequenceNumber(SEQ_NUMBER)); producer.sendInternal(destination, msg); verify(amazonSQSClient).sendMessage(argThat(new sendMessageRequestMatcher(QUEUE_URL, messageBody, SQSMessage.TEXT_MESSAGE_TYPE, GROUP_ID, DEDUP_ID))); verify(msg).setJMSDestination(destination); verify(msg).setJMSMessageID("ID:" + MESSAGE_ID); verify(msg).setSQSMessageId(MESSAGE_ID); verify(msg).setSequenceNumber(SEQ_NUMBER); }
Example #20
Source File: QueueMessageChannelTest.java From spring-cloud-aws with Apache License 2.0 | 6 votes |
@Test void sendMessage_withMimeTypeAsStringHeader_shouldPassItAsMessageAttribute() throws Exception { // Arrange AmazonSQSAsync amazonSqs = mock(AmazonSQSAsync.class); QueueMessageChannel messageChannel = new QueueMessageChannel(amazonSqs, "http://testQueue"); String mimeTypeAsString = new MimeType("test", "plain", Charset.forName("UTF-8")) .toString(); Message<String> message = MessageBuilder.withPayload("Hello") .setHeader(MessageHeaders.CONTENT_TYPE, mimeTypeAsString).build(); ArgumentCaptor<SendMessageRequest> sendMessageRequestArgumentCaptor = ArgumentCaptor .forClass(SendMessageRequest.class); when(amazonSqs.sendMessage(sendMessageRequestArgumentCaptor.capture())) .thenReturn(new SendMessageResult()); // Act boolean sent = messageChannel.send(message); // Assert assertThat(sent).isTrue(); assertThat(sendMessageRequestArgumentCaptor.getValue().getMessageAttributes() .get(MessageHeaders.CONTENT_TYPE).getStringValue()) .isEqualTo(mimeTypeAsString); }
Example #21
Source File: QueueMessageChannelTest.java From spring-cloud-aws with Apache License 2.0 | 6 votes |
@Test void sendMessage_serviceThrowsError_throwsMessagingException() throws Exception { // Arrange AmazonSQSAsync amazonSqs = mock(AmazonSQSAsync.class); Message<String> stringMessage = MessageBuilder.withPayload("message content") .build(); MessageChannel messageChannel = new QueueMessageChannel(amazonSqs, "http://testQueue"); when(amazonSqs .sendMessage(new SendMessageRequest("http://testQueue", "message content") .withDelaySeconds(0).withMessageAttributes(isNotNull()))) .thenThrow(new AmazonServiceException("wanted error")); // Assert assertThatThrownBy(() -> messageChannel.send(stringMessage)) .isInstanceOf(MessagingException.class) .hasMessageContaining("wanted error"); }
Example #22
Source File: QueueMessageChannelTest.java From spring-cloud-aws with Apache License 2.0 | 6 votes |
@Test void sendMessage_validTextMessage_returnsTrue() throws Exception { // Arrange AmazonSQSAsync amazonSqs = mock(AmazonSQSAsync.class); ArgumentCaptor<SendMessageRequest> sendMessageRequestArgumentCaptor = ArgumentCaptor .forClass(SendMessageRequest.class); when(amazonSqs.sendMessage(sendMessageRequestArgumentCaptor.capture())) .thenReturn(new SendMessageResult()); Message<String> stringMessage = MessageBuilder.withPayload("message content") .build(); MessageChannel messageChannel = new QueueMessageChannel(amazonSqs, "http://testQueue"); // Act boolean sent = messageChannel.send(stringMessage); // Assert verify(amazonSqs, only()).sendMessage(any(SendMessageRequest.class)); assertThat(sendMessageRequestArgumentCaptor.getValue().getMessageBody()) .isEqualTo("message content"); assertThat(sent).isTrue(); }
Example #23
Source File: AmazonSQSStubTest.java From aws-java-sdk-stubs with Apache License 2.0 | 6 votes |
@Test public void sendAndReceiveMessage() { final String queueName = "bizo"; final String messageBody = "hi everybody"; final CreateQueueRequest createQueueRequest = new CreateQueueRequest().withQueueName(queueName); sqs.createQueue(createQueueRequest); final GetQueueUrlRequest getQueueUrlRequest = new GetQueueUrlRequest().withQueueName(queueName); final GetQueueUrlResult getQueueUrlResult = sqs.getQueueUrl(getQueueUrlRequest); final String queueUrl = getQueueUrlResult.getQueueUrl(); final SendMessageRequest sendMessageRequest = new SendMessageRequest().withQueueUrl(queueUrl).withMessageBody(messageBody); sqs.sendMessage(sendMessageRequest); final int maxNumberOfMessages = 10; final ReceiveMessageRequest receiveMessageRequest = new ReceiveMessageRequest().withQueueUrl(queueUrl).withMaxNumberOfMessages(maxNumberOfMessages); final ReceiveMessageResult receiveMessageResult = sqs.receiveMessage(receiveMessageRequest); final List<Message> messages = receiveMessageResult.getMessages(); assertThat(messages.size(), equalTo(1)); assertThat(messages.get(0).getBody(), equalTo(messageBody)); }
Example #24
Source File: SqsClient.java From kafka-connect-sqs with Apache License 2.0 | 6 votes |
/** * Send a message to an SQS queue. * * @param url SQS queue url. * @param body The message to send. * @param groupId Optional group identifier (fifo queues only). * @param messageId Optional message identifier (fifo queues only). * @return */ public String send(final String url, final String body, final String groupId, final String messageId) { log.debug(".send: queue={}, gid={}, mid={}", url, groupId, messageId); Guard.verifyValidUrl(url); // Guard.verifyNotNullOrEmpty( body, "message body" ) ; if (!isValidState()) { throw new IllegalStateException("AmazonSQS client is not initialized"); } final boolean fifo = isFifo(url); final SendMessageRequest request = new SendMessageRequest(url, body); if (fifo) { Guard.verifyNotNullOrEmpty(groupId, "groupId"); Guard.verifyNotNullOrEmpty(messageId, "messageId"); request.setMessageGroupId(groupId); request.setMessageDeduplicationId(messageId); } final SendMessageResult result = client.sendMessage(request); log.debug(".send-message.OK: queue={}, result={}", url, result); return fifo ? result.getSequenceNumber() : result.getMessageId(); }
Example #25
Source File: AmazonSQSExtendedClientTest.java From amazon-sqs-java-extended-client-lib with Apache License 2.0 | 5 votes |
@Test public void testWhenSendMessageWithAlwaysThroughS3AndMessageIsSmallThenItIsStillStoredInS3() { int messageLength = LESS_THAN_SQS_SIZE_LIMIT; String messageBody = generateStringWithLength(messageLength); ExtendedClientConfiguration extendedClientConfiguration = new ExtendedClientConfiguration() .withLargePayloadSupportEnabled(mockS3, S3_BUCKET_NAME).withAlwaysThroughS3(true); AmazonSQS sqsExtended = spy(new AmazonSQSExtendedClient(mock(AmazonSQSClient.class), extendedClientConfiguration)); SendMessageRequest messageRequest = new SendMessageRequest(SQS_QUEUE_URL, messageBody); sqsExtended.sendMessage(messageRequest); verify(mockS3, times(1)).putObject(isA(PutObjectRequest.class)); }
Example #26
Source File: AWSSQSClient.java From camel-kafka-connector with Apache License 2.0 | 5 votes |
public void send(String queue, String body) { final String queueUrl = getQueue(queue); LOG.debug("Sending messages to {}", queueUrl); SendMessageRequest request = new SendMessageRequest() .withQueueUrl(queueUrl) .withMessageBody(body); sqs.sendMessage(request); }
Example #27
Source File: SQSResourcesIntegrationTest.java From aws-sdk-java-resources with Apache License 2.0 | 5 votes |
/** * Tests sending of message with message attributes. Asserts that the * message received has the attributes. Also changes the visibility of the * messages and tries to retrieve them. Performs delete action on the * message to the delete it from the queue. */ @Test @Ignore public void testSendReceiveMessageAttributes() throws InterruptedException { SendMessageResult sendMessageResult = queue .sendMessage(new SendMessageRequest().withMessageBody( TEST_MESSAGE_ATTRIBUTES).withMessageAttributes( ImmutableMapParameter.of( "testAttribute", new MessageAttributeValue().withDataType( "String").withStringValue( "testAttributeValue")))); List<Message> messages = waitForMessagesFromQueue(new ReceiveMessageRequest() .withMessageAttributeNames("testAttribute")); assertNotNull(messages); assertEquals(1, messages.size()); Message message = messages.get(0); assertMessage(TEST_MESSAGE_ATTRIBUTES, sendMessageResult.getMessageId(), sendMessageResult.getMD5OfMessageBody(), message); Map<String, MessageAttributeValue> messageAttributes = message .getMessageAttributes(); assertNotNull(messageAttributes); assertTrue(messageAttributes.containsKey("testAttribute")); assertEquals(messageAttributes.get("testAttribute").getStringValue(), "testAttributeValue"); message.changeVisibility(10); messages = waitForMessagesFromQueue(null); message.delete(); }
Example #28
Source File: AmazonSQSExtendedClientTest.java From amazon-sqs-java-extended-client-lib with Apache License 2.0 | 5 votes |
@Test public void testWhenSmallMessageIsSentThenNoAttributeIsAdded() { int messageLength = LESS_THAN_SQS_SIZE_LIMIT; String messageBody = generateStringWithLength(messageLength); SendMessageRequest messageRequest = new SendMessageRequest(SQS_QUEUE_URL, messageBody); extendedSqsWithDefaultConfig.sendMessage(messageRequest); ArgumentCaptor<SendMessageRequest> sendMessageRequestCaptor = ArgumentCaptor.forClass(SendMessageRequest.class); verify(mockSqsBackend).sendMessage(sendMessageRequestCaptor.capture()); Map<String, MessageAttributeValue> attributes = sendMessageRequestCaptor.getValue().getMessageAttributes(); Assert.assertTrue(attributes.isEmpty()); }
Example #29
Source File: AmazonSQSExtendedClientTest.java From amazon-sqs-java-extended-client-lib with Apache License 2.0 | 5 votes |
@Test public void testWhenSendMessageWithSetMessageSizeThresholdThenThresholdIsHonored() { int messageLength = ARBITRATY_SMALLER_THRESSHOLD * 2; String messageBody = generateStringWithLength(messageLength); ExtendedClientConfiguration extendedClientConfiguration = new ExtendedClientConfiguration() .withLargePayloadSupportEnabled(mockS3, S3_BUCKET_NAME).withMessageSizeThreshold(ARBITRATY_SMALLER_THRESSHOLD); AmazonSQS sqsExtended = spy(new AmazonSQSExtendedClient(mock(AmazonSQSClient.class), extendedClientConfiguration)); SendMessageRequest messageRequest = new SendMessageRequest(SQS_QUEUE_URL, messageBody); sqsExtended.sendMessage(messageRequest); verify(mockS3, times(1)).putObject(isA(PutObjectRequest.class)); }
Example #30
Source File: SQSMessageProducerTest.java From amazon-sqs-java-messaging-lib with Apache License 2.0 | 5 votes |
/** * Test sendInternal input with SQSByteMessage */ @Test public void testSendInternalSQSByteMessage() throws JMSException { SQSBytesMessage msg = spy(new SQSBytesMessage()); msg.writeByte((byte)0); msg.reset(); Map<String, MessageAttributeValue> messageAttributes = createMessageAttribute("byte"); String messageId = "MessageId"; when(amazonSQSClient.sendMessage(any(SendMessageRequest.class))) .thenReturn(new SendMessageResult().withMessageId(MESSAGE_ID_1)) .thenReturn(new SendMessageResult().withMessageId(MESSAGE_ID_2)); producer.sendInternal(destination, msg); /* * Re send the message */ msg.clearBody(); msg.writeInt(42); producer.sendInternal(destination, msg); List<String> messagesBody = Arrays.asList("AA==", "AAAAKg=="); verify(amazonSQSClient, times(2)).sendMessage(argThat(new sendMessageRequestMatcher(QUEUE_URL, messagesBody, messageAttributes))); verify(msg, times(2)).setJMSDestination(destination); verify(msg).setJMSMessageID("ID:" + MESSAGE_ID_1); verify(msg).setJMSMessageID("ID:" + MESSAGE_ID_2); verify(msg).setSQSMessageId(MESSAGE_ID_1); verify(msg).setSQSMessageId(MESSAGE_ID_2); }