Java Code Examples for com.amazonaws.services.sqs.model.ReceiveMessageRequest#setMaxNumberOfMessages()

The following examples show how to use com.amazonaws.services.sqs.model.ReceiveMessageRequest#setMaxNumberOfMessages() . 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: SqsUnboundedReader.java    From beam with Apache License 2.0 6 votes vote down vote up
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 2
Source File: SpringCloudSQSLiveTest.java    From tutorials with MIT License 6 votes vote down vote up
@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 3
Source File: SpringCloudSQSLiveTest.java    From tutorials with MIT License 6 votes vote down vote up
@Test
public void whenConvertedMessageSentAndVerified_thenSuccess() throws InterruptedException, IOException {
    
    Greeting message = new Greeting("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(new ObjectMapper().readValue(result.getMessages().get(0).getBody(), Greeting.class)).isEqualTo(message);
    
    // Delete message so that it doen't interfere with other test
    amazonSQS.deleteMessage(sendQueueURl, result.getMessages().get(0).getReceiptHandle());
}
 
Example 4
Source File: RequestFactoryImpl.java    From aws-codecommit-trigger-plugin with Apache License 2.0 5 votes vote down vote up
@Override
public ReceiveMessageRequest createReceiveMessageRequest(String queueUrl, final int maxNumberMessages, final int waitTimeSeconds) {
    final ReceiveMessageRequest request = new ReceiveMessageRequest(queueUrl);
    request.setMaxNumberOfMessages(maxNumberMessages);
    request.setWaitTimeSeconds(waitTimeSeconds);
    return request;
}
 
Example 5
Source File: SqsManager.java    From aws-cloudtrail-processing-library with Apache License 2.0 5 votes vote down vote up
/**
 * 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 6
Source File: CloudtrailSQSClient.java    From graylog-plugin-aws with Apache License 2.0 4 votes vote down vote up
public List<CloudtrailSNSNotification> getNotifications() {

        LOG.debug("Fetching SQS CloudTrail notifications.");

        List<CloudtrailSNSNotification> notifications = Lists.newArrayList();

        ReceiveMessageRequest request = new ReceiveMessageRequest(queueName);
        request.setMaxNumberOfMessages(10);
        ReceiveMessageResult result = sqs.receiveMessage(request);

        LOG.debug("Received [{}] SQS CloudTrail notifications.", result.getMessages().size());
        CloudtrailSNSNotificationParser parser = new CloudtrailSNSNotificationParser(objectMapper);
        LOG.debug("Finished parsing notifications.");

        for (Message message : result.getMessages()) {
            notifications.addAll(parser.parse(message));
        }

        LOG.debug("Returning notifications.");

        return notifications;
    }