com.amazonaws.services.sqs.model.ReceiveMessageRequest Java Examples
The following examples show how to use
com.amazonaws.services.sqs.model.ReceiveMessageRequest.
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 | 6 votes |
private AmazonSQSAsync createAmazonSqs() { AmazonSQSAsync amazonSqs = mock(AmazonSQSAsync.class); GetQueueUrlResult queueUrl = new GetQueueUrlResult(); queueUrl.setQueueUrl("https://queue-url.com"); when(amazonSqs.getQueueUrl(any(GetQueueUrlRequest.class))).thenReturn(queueUrl); ReceiveMessageResult receiveMessageResult = new ReceiveMessageResult(); com.amazonaws.services.sqs.model.Message message = new com.amazonaws.services.sqs.model.Message(); message.setBody("My message"); receiveMessageResult.withMessages(message); when(amazonSqs.receiveMessage(any(ReceiveMessageRequest.class))) .thenReturn(receiveMessageResult); return amazonSqs; }
Example #2
Source File: SQSMessageConsumerPrefetchTest.java From amazon-sqs-java-messaging-lib with Apache License 2.0 | 6 votes |
/** * Test received messages with timeout */ @Test public void testReceiveNoWaitEmpty() throws InterruptedException, JMSException { /* * Set up consumer prefetch and time stamps */ consumerPrefetch.running = true; if (numberOfMessagesToPrefetch == 0) { when(amazonSQSClient.receiveMessage(any(ReceiveMessageRequest.class))) .thenReturn(new ReceiveMessageResult()); } /* * Call receive messages */ SQSMessage msg = (SQSMessage) consumerPrefetch.receiveNoWait(); assertNull(msg); // Ensure the messagesRequested counter is reset correctly assertEquals(0, consumerPrefetch.messagesRequested); }
Example #3
Source File: MockSQSQueue.java From amazon-sqs-java-temporary-queues-client with Apache License 2.0 | 6 votes |
public ReceiveMessageResult receiveMessage(ReceiveMessageRequest request) { Integer waitTimeSeconds = request.getWaitTimeSeconds(); long timeout = waitTimeSeconds != null ? waitTimeSeconds : 0; try { MessageContent messageContent = visibleMessages.poll(timeout, TimeUnit.SECONDS); ReceiveMessageResult result = new ReceiveMessageResult(); if (messageContent != null) { Message message = messageContent.toMessage(); String receiptHandle = UUID.randomUUID().toString(); inflight.put(receiptHandle, messageContent); message.withReceiptHandle(receiptHandle); result.withMessages(message); } return result; } catch (InterruptedException e) { // Imitate what the real SDK does throw new AmazonClientException(e); } }
Example #4
Source File: AmazonSQSVirtualQueuesClientIT.java From amazon-sqs-java-temporary-queues-client with Apache License 2.0 | 6 votes |
@Test public void ReceiveMessageWaitTimeSecondsNull() { CreateQueueRequest request = new CreateQueueRequest() .withQueueName("ReceiveMessageWaitTimeSecondsNull") .addAttributesEntry(AmazonSQSVirtualQueuesClient.VIRTUAL_QUEUE_HOST_QUEUE_ATTRIBUTE, hostQueueUrl) .addAttributesEntry(AmazonSQSIdleQueueDeletingClient.IDLE_QUEUE_RETENTION_PERIOD, "5"); String virtualQueueUrl = client.createQueue(request).getQueueUrl(); // Do Receive message request with null WaitTimeSeconds. ReceiveMessageRequest receiveRequest = new ReceiveMessageRequest() .withQueueUrl(virtualQueueUrl); try { assertEquals(0, client.receiveMessage(receiveRequest).getMessages().size()); } catch (NullPointerException npe) { fail("NPE not expected with null WaitTimeSeconds on ReceiveMessageRequest"); } }
Example #5
Source File: AWSSQSClient.java From camel-kafka-connector with Apache License 2.0 | 6 votes |
public void receive(String queue, Predicate<List<Message>> predicate) { final String queueUrl = getQueue(queue); LOG.debug("Consuming messages from {}", queueUrl); final ReceiveMessageRequest request = new ReceiveMessageRequest(queueUrl) .withWaitTimeSeconds(maxWaitTime) .withMaxNumberOfMessages(maxNumberOfMessages); while (true) { ReceiveMessageResult result = sqs.receiveMessage(request); List<Message> messages = result.getMessages(); if (!predicate.test(messages)) { return; } } }
Example #6
Source File: ReceiveQueueBuffer.java From amazon-sqs-java-temporary-queues-client with Apache License 2.0 | 6 votes |
/** * Submits the request for retrieval of messages from the queue and returns a future that will * be signalled when the request is satisfied. The future may already be signalled by the time * it is returned. * * @return never null */ public Future<ReceiveMessageResult> receiveMessageAsync(ReceiveMessageRequest rq) { if (shutDown) { throw new AmazonClientException("The buffer has been shut down."); } // issue the future... int numMessages = 10; if (rq.getMaxNumberOfMessages() != null) { numMessages = rq.getMaxNumberOfMessages(); } long waitTimeNanos; if (rq.getWaitTimeSeconds() != null) { waitTimeNanos = TimeUnit.SECONDS.toNanos(rq.getWaitTimeSeconds()); } else { waitTimeNanos = defaultWaitTimeNanos; } ReceiveMessageFuture toReturn = issueFuture(numMessages, waitTimeNanos); // attempt to satisfy it right away... satisfyFuturesFromBuffer(); toReturn.startWaitTimer(); return toReturn; }
Example #7
Source File: AmazonSQSIdleQueueDeletingClient.java From amazon-sqs-java-temporary-queues-client with Apache License 2.0 | 6 votes |
@Override public ReceiveMessageResult receiveMessage(ReceiveMessageRequest request) { // Here we have to also fetch from the backup queue if we created it. String queueUrl = request.getQueueUrl(); String alternateQueueUrl = alternateQueueName(queueUrl); QueueMetadata alternateMetadata = queues.get(alternateQueueUrl); if (alternateMetadata != null) { ReceiveQueueBuffer buffer = alternateMetadata.buffer; ReceiveMessageRequest alternateRequest = request.clone().withQueueUrl(alternateQueueUrl); buffer.submit(executor, () -> receiveIgnoringNonExistantQueue(request), queueUrl, request.getVisibilityTimeout()); buffer.submit(executor, () -> receiveIgnoringNonExistantQueue(alternateRequest), queueUrl, request.getVisibilityTimeout()); Future<ReceiveMessageResult> receiveFuture = buffer.receiveMessageAsync(request); return SQSQueueUtils.waitForFuture(receiveFuture); } else { try { heartbeatToQueueIfNecessary(queueUrl); return super.receiveMessage(request); } catch (QueueDoesNotExistException e) { request.setQueueUrl(recreateQueue(queueUrl)); return super.receiveMessage(request); } } }
Example #8
Source File: SQSScanWorkflow.java From emodb with Apache License 2.0 | 6 votes |
@Override public List<ScanRangeTask> claimScanRangeTasks(int max, Duration ttl) { if (max == 0) { return ImmutableList.of(); } List<Message> messages = _sqs.receiveMessage(new ReceiveMessageRequest() .withQueueUrl(getQueueUrl(_pendingScanRangeQueue)) .withMaxNumberOfMessages(Math.min(max, 10)) // SQS cannot claim more than 10 messages .withVisibilityTimeout(toSeconds(ttl)) ).getMessages(); return FluentIterable.from(messages) .transform(new Function<Message, ScanRangeTask>() { @Override public ScanRangeTask apply(Message message) { QueueScanRangeTask task = JsonHelper.fromJson(message.getBody(), QueueScanRangeTask.class); task.setMessageId(message.getReceiptHandle()); return task; } }) .toList(); }
Example #9
Source File: SQSScanWorkflow.java From emodb with Apache License 2.0 | 6 votes |
@Override public List<ScanRangeComplete> claimCompleteScanRanges(Duration ttl) { List<Message> messages = _sqs.receiveMessage(new ReceiveMessageRequest() .withQueueUrl(getQueueUrl(_completeScanRangeQueue)) .withMaxNumberOfMessages(10) .withVisibilityTimeout(toSeconds(ttl)) ).getMessages(); return FluentIterable.from(messages) .transform(new Function<Message, ScanRangeComplete>() { @Override public ScanRangeComplete apply(Message message) { QueueScanRangeComplete completion = JsonHelper.fromJson(message.getBody(), QueueScanRangeComplete.class); completion.setMessageId(message.getReceiptHandle()); return completion; } }) .toList(); }
Example #10
Source File: SqsUnboundedReader.java From beam with Apache License 2.0 | 6 votes |
private void pull() { final ReceiveMessageRequest receiveMessageRequest = new ReceiveMessageRequest(source.getRead().queueUrl()); receiveMessageRequest.setMaxNumberOfMessages(MAX_NUMBER_OF_MESSAGES); receiveMessageRequest.setAttributeNames( Arrays.asList(MessageSystemAttributeName.SentTimestamp.toString())); final ReceiveMessageResult receiveMessageResult = source.getSqs().receiveMessage(receiveMessageRequest); final List<Message> messages = receiveMessageResult.getMessages(); if (messages == null || messages.isEmpty()) { return; } for (Message message : messages) { messagesNotYetRead.add(message); } }
Example #11
Source File: HerdApiClientOperations.java From herd with Apache License 2.0 | 6 votes |
/** * Gets BusinessObjectDataKey from SQS message * * @param client the AWS SQS client * @param queueUrl the AWS SQS queue url * * @return BusinessObjectDataKey * @throws IOException if fails to retrieve BusinessObjectDataKey from SQS message * @throws ApiException if fails to make API call */ @Retryable(value = ApiException.class, backoff = @Backoff(delay = 2000, multiplier = 2)) BusinessObjectDataKey getBdataKeySqs(AmazonSQS client, String queueUrl) throws IOException, ApiException { ReceiveMessageRequest receiveMessageRequest = new ReceiveMessageRequest().withMaxNumberOfMessages(MAX_NUM_MESSAGES).withQueueUrl(queueUrl).withWaitTimeSeconds(WAIT_TIME_SECS) .withVisibilityTimeout(VISIBILITY_TIMEOUT_SECS); LOGGER.info("Checking queue"); ReceiveMessageResult receiveMessageResult = client.receiveMessage(receiveMessageRequest); if (receiveMessageResult != null && receiveMessageResult.getMessages() != null && receiveMessageResult.getMessages().size() > 0) { List<Message> sqsMessageList = receiveMessageResult.getMessages(); LOGGER.info("Scanning {} messages for {} and {}", sqsMessageList.size(), SEARCH_KEYWORD_1, SEARCH_KEYWORD_2); // Get message type BUS_OBJCT_DATA_STTS_CHG for (Message sqsMessage : sqsMessageList) { String receivedMessageBody = sqsMessage.getBody(); if (receivedMessageBody.contains(SEARCH_KEYWORD_1) && receivedMessageBody.contains(SEARCH_KEYWORD_2)) { LOGGER.info("Received Message: {}", receivedMessageBody); return mapJsontoBdataKey(receivedMessageBody).getBusinessObjectDataKey(); } } } throw new ApiException("No SQS message found in queue: " + queueUrl); }
Example #12
Source File: AmazonSQSExtendedClientTest.java From amazon-sqs-java-extended-client-lib with Apache License 2.0 | 6 votes |
@Test public void testReceiveMessageMultipleTimesDoesNotAdditionallyAlterReceiveMessageRequest() { ExtendedClientConfiguration extendedClientConfiguration = new ExtendedClientConfiguration() .withLargePayloadSupportEnabled(mockS3, S3_BUCKET_NAME); AmazonSQS sqsExtended = spy(new AmazonSQSExtendedClient(mockSqsBackend, extendedClientConfiguration)); when(mockSqsBackend.receiveMessage(isA(ReceiveMessageRequest.class))).thenReturn(new ReceiveMessageResult()); ReceiveMessageRequest messageRequest = new ReceiveMessageRequest(); ReceiveMessageRequest expectedRequest = new ReceiveMessageRequest() .withMessageAttributeNames(SQSExtendedClientConstants.RESERVED_ATTRIBUTE_NAME); sqsExtended.receiveMessage(messageRequest); Assert.assertEquals(expectedRequest, messageRequest); sqsExtended.receiveMessage(messageRequest); Assert.assertEquals(expectedRequest, messageRequest); }
Example #13
Source File: SQSSubscriber.java From echo with Apache License 2.0 | 6 votes |
private void listenForMessages() { while (isEnabled.get()) { ReceiveMessageResult receiveMessageResult = amazonSQS.receiveMessage( new ReceiveMessageRequest(queueId) .withMaxNumberOfMessages(AWS_MAX_NUMBER_OF_MESSAGES) .withVisibilityTimeout(subscription.getVisibilityTimeout()) .withWaitTimeSeconds(subscription.getWaitTimeSeconds()) .withMessageAttributeNames("All")); if (receiveMessageResult.getMessages().isEmpty()) { log.debug("Received no messages for queue: {}", queueARN); continue; } receiveMessageResult.getMessages().forEach(this::handleMessage); } }
Example #14
Source File: SqsClient.java From kafka-connect-sqs with Apache License 2.0 | 6 votes |
/** * Receive messages from the SQS queue. * * @param url SQS queue url. * @param maxMessages Maximum number of messages to receive for this call. * @param waitTimeSeconds Time to wait, in seconds, for messages to arrive. * @return Collection of messages received. */ public List<Message> receive(final String url, final int maxMessages, final int waitTimeSeconds) { log.debug(".receive:queue={}, max={}, wait={}", url, maxMessages, waitTimeSeconds); Guard.verifyValidUrl(url); Guard.verifyNonNegative(waitTimeSeconds, "sqs.wait.time.seconds"); Guard.verifyInRange(maxMessages, 0, 10, "sqs.max.messages"); if (!isValidState()) { throw new IllegalStateException("AmazonSQS client is not initialized"); } // // Receive messages from queue // final ReceiveMessageRequest receiveMessageRequest = new ReceiveMessageRequest(url) .withMaxNumberOfMessages(maxMessages).withWaitTimeSeconds(waitTimeSeconds).withAttributeNames(""); final ReceiveMessageResult result = client.receiveMessage(receiveMessageRequest); final List<Message> messages = result.getMessages(); log.debug(".receive:{} messages, url={}, rc={}", messages.size(), url, result.getSdkHttpMetadata().getHttpStatusCode()); return messages; }
Example #15
Source File: SpringCloudSQSLiveTest.java From tutorials with MIT License | 6 votes |
@Test public void whenMessageSentAndVerified_thenSuccess() throws InterruptedException { String message = "Hello World"; springCloudSQS.send(sendQueueName, message); AmazonSQS amazonSQS = SpringCloudAwsTestUtil.amazonSQS(); ReceiveMessageRequest request = new ReceiveMessageRequest(sendQueueURl); request.setMaxNumberOfMessages(1); ReceiveMessageResult result = null; do { result = amazonSQS.receiveMessage(request); if (result.getMessages().size() == 0) { logger.info("Message not received at first time, waiting for 1 second"); } } while (result.getMessages().size() == 0); assertThat(result.getMessages().get(0).getBody()).isEqualTo(message); // Delete message so that it doen't interfere with other test amazonSQS.deleteMessage(sendQueueURl, result.getMessages().get(0).getReceiptHandle()); }
Example #16
Source File: QueueMessageChannelTest.java From spring-cloud-aws with Apache License 2.0 | 6 votes |
@Test void receiveMessage_withoutDefaultTimeout_returnsNull() throws Exception { // Arrange AmazonSQSAsync amazonSqs = mock(AmazonSQSAsync.class); when(amazonSqs.receiveMessage(new ReceiveMessageRequest("http://testQueue") .withWaitTimeSeconds(0).withMaxNumberOfMessages(1) .withAttributeNames(QueueMessageChannel.ATTRIBUTE_NAMES) .withMessageAttributeNames("All"))).thenReturn( new ReceiveMessageResult().withMessages(Collections.emptyList())); PollableChannel messageChannel = new QueueMessageChannel(amazonSqs, "http://testQueue"); // Act Message<?> receivedMessage = messageChannel.receive(0); // Assert assertThat(receivedMessage).isNull(); }
Example #17
Source File: QueueMessageChannelTest.java From spring-cloud-aws with Apache License 2.0 | 6 votes |
@Test void receiveMessage_withSpecifiedTimeout_returnsNull() throws Exception { // Arrange AmazonSQSAsync amazonSqs = mock(AmazonSQSAsync.class); when(amazonSqs.receiveMessage(new ReceiveMessageRequest("http://testQueue") .withWaitTimeSeconds(2).withMaxNumberOfMessages(1) .withAttributeNames(QueueMessageChannel.ATTRIBUTE_NAMES) .withMessageAttributeNames("All"))).thenReturn( new ReceiveMessageResult().withMessages(Collections.emptyList())); PollableChannel messageChannel = new QueueMessageChannel(amazonSqs, "http://testQueue"); // Act Message<?> receivedMessage = messageChannel.receive(2); // Assert assertThat(receivedMessage).isNull(); }
Example #18
Source File: QueueMessageChannelTest.java From spring-cloud-aws with Apache License 2.0 | 6 votes |
@Test void receiveMessage_withSpecifiedTimeout_returnsTextMessage() throws Exception { // Arrange AmazonSQSAsync amazonSqs = mock(AmazonSQSAsync.class); when(amazonSqs.receiveMessage(new ReceiveMessageRequest("http://testQueue") .withWaitTimeSeconds(2).withMaxNumberOfMessages(1) .withAttributeNames(QueueMessageChannel.ATTRIBUTE_NAMES) .withMessageAttributeNames("All"))) .thenReturn(new ReceiveMessageResult().withMessages(Collections .singleton(new com.amazonaws.services.sqs.model.Message() .withBody("content")))); PollableChannel messageChannel = new QueueMessageChannel(amazonSqs, "http://testQueue"); // Act Message<?> receivedMessage = messageChannel.receive(2); // Assert assertThat(receivedMessage).isNotNull(); assertThat(receivedMessage.getPayload()).isEqualTo("content"); }
Example #19
Source File: QueueMessageChannelTest.java From spring-cloud-aws with Apache License 2.0 | 6 votes |
@Test void receiveMessage_withoutTimeout_returnsTextMessage() throws Exception { // Arrange AmazonSQSAsync amazonSqs = mock(AmazonSQSAsync.class); when(amazonSqs.receiveMessage(new ReceiveMessageRequest("http://testQueue") .withWaitTimeSeconds(0).withMaxNumberOfMessages(1) .withAttributeNames(QueueMessageChannel.ATTRIBUTE_NAMES) .withMessageAttributeNames("All"))) .thenReturn(new ReceiveMessageResult().withMessages(Collections .singleton(new com.amazonaws.services.sqs.model.Message() .withBody("content")))); PollableChannel messageChannel = new QueueMessageChannel(amazonSqs, "http://testQueue"); // Act Message<?> receivedMessage = messageChannel.receive(); // Assert assertThat(receivedMessage).isNotNull(); assertThat(receivedMessage.getPayload()).isEqualTo("content"); }
Example #20
Source File: SqsExecutorTest.java From spring-integration-aws with MIT License | 6 votes |
@Test public void correctMD5Test() throws Exception { String payload = "Hello, World"; String messageBody = messageMarshaller.serialize(MessageBuilder .withPayload(payload).build()); com.amazonaws.services.sqs.model.Message sqsMessage = new com.amazonaws.services.sqs.model.Message(); sqsMessage.setBody(messageBody); sqsMessage.setMD5OfBody(new String(Hex.encodeHex(Md5Utils .computeMD5Hash(messageBody.getBytes("UTF-8"))))); ReceiveMessageResult result = new ReceiveMessageResult(); result.setMessages(Collections.singletonList(sqsMessage)); when(mockSQS.receiveMessage(any(ReceiveMessageRequest.class))) .thenReturn(result); Message<?> recvMessage = executor.poll(); assertNotNull("message is not null", recvMessage); Message<?> enclosed = messageMarshaller .deserialize((String) recvMessage.getPayload()); String recvPayload = (String) enclosed.getPayload(); assertEquals("payload must match", payload, recvPayload); }
Example #21
Source File: QueueMessageChannel.java From spring-cloud-aws with Apache License 2.0 | 6 votes |
@Override public Message<String> receive(long timeout) { ReceiveMessageResult receiveMessageResult = this.amazonSqs.receiveMessage( new ReceiveMessageRequest(this.queueUrl).withMaxNumberOfMessages(1) .withWaitTimeSeconds(Long.valueOf(timeout).intValue()) .withAttributeNames(ATTRIBUTE_NAMES) .withMessageAttributeNames(MESSAGE_ATTRIBUTE_NAMES)); if (receiveMessageResult.getMessages().isEmpty()) { return null; } com.amazonaws.services.sqs.model.Message amazonMessage = receiveMessageResult .getMessages().get(0); Message<String> message = createMessage(amazonMessage); this.amazonSqs.deleteMessage(new DeleteMessageRequest(this.queueUrl, amazonMessage.getReceiptHandle())); return message; }
Example #22
Source File: SQSSubscriber.java From kork with Apache License 2.0 | 6 votes |
private void listenForMessages() { while (isEnabled.get()) { ReceiveMessageResult receiveMessageResult = amazonSQS.receiveMessage( new ReceiveMessageRequest(this.subscriptionInfo.queueUrl) .withMaxNumberOfMessages(subscription.getMaxNumberOfMessages()) .withVisibilityTimeout(subscription.getVisibilityTimeout()) .withWaitTimeSeconds(subscription.getWaitTimeSeconds()) .withMessageAttributeNames("All")); if (receiveMessageResult.getMessages().isEmpty()) { log.debug("Received no messages for queue {}", queueARN); continue; } receiveMessageResult.getMessages().forEach(this::handleMessage); } }
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: AmazonSQSMessagingClientWrapperTest.java From amazon-sqs-java-messaging-lib with Apache License 2.0 | 5 votes |
@Test(expected = JMSException.class) public void testReceiveMessageThrowAmazonServiceException() throws JMSException { ReceiveMessageRequest getQueueUrlRequest = new ReceiveMessageRequest(); doThrow(new AmazonServiceException("ase")) .when(amazonSQSClient).receiveMessage(eq(getQueueUrlRequest)); wrapper.receiveMessage(getQueueUrlRequest); }
Example #25
Source File: SimpleMessageListenerContainerTest.java From spring-cloud-aws with Apache License 2.0 | 5 votes |
@Override public ReceiveMessageResult receiveMessage( ReceiveMessageRequest receiveMessageRequest) throws AmazonClientException { if ("http://testQueue.amazonaws.com".equals( receiveMessageRequest.getQueueUrl()) && this.receiveMessageEnabled) { return new ReceiveMessageResult().withMessages(new Message() .withBody("Hello").withReceiptHandle("ReceiptHandle")); } else { return new ReceiveMessageResult(); } }
Example #26
Source File: SimpleMessageListenerContainerTest.java From spring-cloud-aws with Apache License 2.0 | 5 votes |
private static void mockReceiveMessage(AmazonSQSAsync sqs, String queueUrl, String messageContent, String receiptHandle) { when(sqs.receiveMessage(new ReceiveMessageRequest(queueUrl) .withAttributeNames("All").withMessageAttributeNames("All") .withMaxNumberOfMessages(10).withWaitTimeSeconds(20))) .thenReturn( new ReceiveMessageResult().withMessages( new Message().withBody(messageContent) .withReceiptHandle(receiptHandle)), new ReceiveMessageResult()); }
Example #27
Source File: SqsManager.java From aws-cloudtrail-processing-library with Apache License 2.0 | 5 votes |
/** * Poll SQS queue for incoming messages, filter them, and return a list of SQS Messages. * * @return a list of SQS messages. */ public List<Message> pollQueue() { boolean success = false; ProgressStatus pollQueueStatus = new ProgressStatus(ProgressState.pollQueue, new BasicPollQueueInfo(0, success)); final Object reportObject = progressReporter.reportStart(pollQueueStatus); ReceiveMessageRequest request = new ReceiveMessageRequest().withAttributeNames(ALL_ATTRIBUTES); request.setQueueUrl(config.getSqsUrl()); request.setVisibilityTimeout(config.getVisibilityTimeout()); request.setMaxNumberOfMessages(DEFAULT_SQS_MESSAGE_SIZE_LIMIT); request.setWaitTimeSeconds(DEFAULT_WAIT_TIME_SECONDS); List<Message> sqsMessages = new ArrayList<Message>(); try { ReceiveMessageResult result = sqsClient.receiveMessage(request); sqsMessages = result.getMessages(); logger.info("Polled " + sqsMessages.size() + " sqs messages from " + config.getSqsUrl()); success = true; } catch (AmazonServiceException e) { LibraryUtils.handleException(exceptionHandler, pollQueueStatus, e, "Failed to poll sqs message."); } finally { LibraryUtils.endToProcess(progressReporter, success, pollQueueStatus, reportObject); } return sqsMessages; }
Example #28
Source File: SimpleMessageListenerContainerTest.java From spring-cloud-aws with Apache License 2.0 | 5 votes |
@Bean AmazonSQSAsync amazonSQS() { AmazonSQSAsync mockAmazonSQS = mock(AmazonSQSAsync.class, withSettings().stubOnly()); mockGetQueueUrl(mockAmazonSQS, "testQueue", "http://testQueue.amazonaws.com"); when(mockAmazonSQS.receiveMessage(any(ReceiveMessageRequest.class))) .thenReturn(new ReceiveMessageResult()); when(mockAmazonSQS.getQueueAttributes(any(GetQueueAttributesRequest.class))) .thenReturn(new GetQueueAttributesResult()); return mockAmazonSQS; }
Example #29
Source File: QueueMessagingTemplateTest.java From spring-cloud-aws with Apache License 2.0 | 5 votes |
@Test void receive_withDefaultDestination_useDefaultDestination() { AmazonSQSAsync amazonSqs = createAmazonSqs(); QueueMessagingTemplate queueMessagingTemplate = new QueueMessagingTemplate( amazonSqs); queueMessagingTemplate.setDefaultDestinationName("my-queue"); queueMessagingTemplate.receive(); ArgumentCaptor<ReceiveMessageRequest> sendMessageRequestArgumentCaptor = ArgumentCaptor .forClass(ReceiveMessageRequest.class); verify(amazonSqs).receiveMessage(sendMessageRequestArgumentCaptor.capture()); assertThat(sendMessageRequestArgumentCaptor.getValue().getQueueUrl()) .isEqualTo("https://queue-url.com"); }
Example #30
Source File: QueueMessagingTemplateTest.java From spring-cloud-aws with Apache License 2.0 | 5 votes |
@Test void receive_withDestination_usesDestination() { AmazonSQSAsync amazonSqs = createAmazonSqs(); QueueMessagingTemplate queueMessagingTemplate = new QueueMessagingTemplate( amazonSqs); queueMessagingTemplate.receive("my-queue"); ArgumentCaptor<ReceiveMessageRequest> sendMessageRequestArgumentCaptor = ArgumentCaptor .forClass(ReceiveMessageRequest.class); verify(amazonSqs).receiveMessage(sendMessageRequestArgumentCaptor.capture()); assertThat(sendMessageRequestArgumentCaptor.getValue().getQueueUrl()) .isEqualTo("https://queue-url.com"); }