当前位置: 首页>>代码示例>>Java>>正文


Java ReceiveMessageRequest类代码示例

本文整理汇总了Java中com.amazonaws.services.sqs.model.ReceiveMessageRequest的典型用法代码示例。如果您正苦于以下问题:Java ReceiveMessageRequest类的具体用法?Java ReceiveMessageRequest怎么用?Java ReceiveMessageRequest使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ReceiveMessageRequest类属于com.amazonaws.services.sqs.model包,在下文中一共展示了ReceiveMessageRequest类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testPurgeQueue_shouldRemoveAll

import com.amazonaws.services.sqs.model.ReceiveMessageRequest; //导入依赖的package包/类
@Test
public void testPurgeQueue_shouldRemoveAll() {
  // create queue
  CreateQueueResult createdQueue = sqs.createQueue(new CreateQueueRequest().withQueueName("tea-earl-grey-queue"));
  // send messages
  String messageBody = "{\"life-universe-everything\":42}";
  sqs.sendMessage(new SendMessageRequest().withDelaySeconds(0).withMessageBody(messageBody)
      .withMessageGroupId("some-group-id-123").withQueueUrl(createdQueue.getQueueUrl()));
  String messageBody2 = "{\"dead-emptyness-nothing\":24}";
  sqs.sendMessage(new SendMessageRequest().withDelaySeconds(0).withMessageBody(messageBody2)
      .withMessageGroupId("some-group-id-123").withQueueUrl(createdQueue.getQueueUrl()));
  
  // purge queues
  PurgeQueueResult result = sqs.purgeQueue(new PurgeQueueRequest().withQueueUrl(createdQueue.getQueueUrl()));
  assertNotNull("verify that purge queue returned ok", result);
  
  // verify empty queue
  ReceiveMessageResult messageResult = sqs.receiveMessage(new ReceiveMessageRequest()
      .withMaxNumberOfMessages(9).withQueueUrl(createdQueue.getQueueUrl()).withVisibilityTimeout(10)
      .withWaitTimeSeconds(0));
  assertEquals("verify that queue is empty", 0, messageResult.getMessages().size());
  
  // cleanup
  getQueues().remove("tea-earl-grey-queue");
}
 
开发者ID:daflockinger,项目名称:unitstack,代码行数:26,代码来源:MockSqsTest.java

示例2: getMessages

import com.amazonaws.services.sqs.model.ReceiveMessageRequest; //导入依赖的package包/类
public List<QueueMessage> getMessages() {

        ReceiveMessageRequest receiveMessageRequest = new ReceiveMessageRequest(_queueDns);
        List<Message> messages = _sqs.receiveMessage(receiveMessageRequest).getMessages();

        List<QueueMessage> deserializedMessages = new ArrayList<>();

        for (Message message : messages) {
            String body = message.getBody();
            QueueMessage qm = _gson.fromJson(body, QueueMessage.class);
            deserializedMessages.add(qm);

            System.out.println("query time: " + qm.queryExecutionTime);
            System.out.println("exec time: " + qm.totalExecutionTime);
            System.out.println("Has ex: " + qm.hasException);
            System.out.println("ex message: " + qm.exceptionMessage + "\n");

            String receiptHandle = message.getReceiptHandle();
            _sqs.deleteMessage(new DeleteMessageRequest(_queueDns, receiptHandle));
        }

        return deserializedMessages;
    }
 
开发者ID:hunterSThompson,项目名称:aws-ski-resort,代码行数:24,代码来源:QueueService.java

示例3: testFirstCallToReceiveMessagesReturnsOneMessage

import com.amazonaws.services.sqs.model.ReceiveMessageRequest; //导入依赖的package包/类
@Test(timeout = 5000)
public void testFirstCallToReceiveMessagesReturnsOneMessage() {
    final AmazonSQSClient sqs = Mockito.mock(AmazonSQSClient.class);
    final String queueName = "queue";
    Mockito.when(sqs.getQueueUrl(queueName)).thenAnswer(x -> new GetQueueUrlResult().withQueueUrl(queueName));
    Mockito.when(sqs.receiveMessage(Mockito.<ReceiveMessageRequest>any()))
            .thenReturn(new ReceiveMessageResult().withMessages(new Message().withBody("body1")));
    Sqs.queueName(queueName) //
            .sqsFactory(() -> sqs) //
            .messages() //
            .map(m -> m.message()) //
            .doOnError(Throwable::printStackTrace) //
            .take(1) //
            .test() //
            .awaitDone(10, TimeUnit.SECONDS) //
            .assertComplete() //
            .assertValue("body1");
    final InOrder inorder = Mockito.inOrder(sqs);
    inorder.verify(sqs, Mockito.atLeastOnce()).getQueueUrl(queueName);
    inorder.verify(sqs, Mockito.times(1)).receiveMessage(Mockito.<ReceiveMessageRequest>any());
    inorder.verify(sqs, Mockito.times(1)).shutdown();
    inorder.verifyNoMoreInteractions();
}
 
开发者ID:davidmoten,项目名称:rxjava2-aws,代码行数:24,代码来源:SqsTest.java

示例4: testFirstCallToReceiveMessagesReturnsOneMessageAndHonoursBackpressure

import com.amazonaws.services.sqs.model.ReceiveMessageRequest; //导入依赖的package包/类
@Test(timeout = 5000)
public void testFirstCallToReceiveMessagesReturnsOneMessageAndHonoursBackpressure() {
    final AmazonSQSClient sqs = Mockito.mock(AmazonSQSClient.class);
    final String queueName = "queue";
    Mockito.when(sqs.getQueueUrl(queueName)).thenAnswer(x -> new GetQueueUrlResult().withQueueUrl(queueName));
    Mockito.when(sqs.receiveMessage(Mockito.<ReceiveMessageRequest>any()))
            .thenReturn(new ReceiveMessageResult().withMessages(new Message().withBody("body1")));
    Sqs.queueName(queueName) //
            .sqsFactory(() -> sqs) //
            .messages() //
            .map(m -> m.message()) //
            .doOnError(Throwable::printStackTrace) //
            .test(0) //
            .requestMore(1) //
            .assertValue("body1")//
            .assertNotComplete() //
            .cancel();
    final InOrder inorder = Mockito.inOrder(sqs);
    inorder.verify(sqs, Mockito.atLeastOnce()).getQueueUrl(queueName);
    inorder.verify(sqs, Mockito.times(1)).receiveMessage(Mockito.<ReceiveMessageRequest>any());
    inorder.verify(sqs, Mockito.times(1)).shutdown();
    inorder.verifyNoMoreInteractions();
}
 
开发者ID:davidmoten,项目名称:rxjava2-aws,代码行数:24,代码来源:SqsTest.java

示例5: testFirstCallToReceiveMessagesReturnsNoMessagesThenSecondCallReturnsTwoMessages

import com.amazonaws.services.sqs.model.ReceiveMessageRequest; //导入依赖的package包/类
@Test(timeout = 5000)
public void testFirstCallToReceiveMessagesReturnsNoMessagesThenSecondCallReturnsTwoMessages() {
    final AmazonSQSClient sqs = Mockito.mock(AmazonSQSClient.class);
    final String queueName = "queue";
    Mockito.when(sqs.getQueueUrl(queueName)).thenAnswer(x -> new GetQueueUrlResult().withQueueUrl(queueName));
    Mockito.when(sqs.receiveMessage(Mockito.<ReceiveMessageRequest>any())).thenReturn(new ReceiveMessageResult())
            .thenReturn(new ReceiveMessageResult().withMessages(new Message().withBody("body1"),
                    new Message().withBody("body2")));
    Sqs.queueName(queueName) //
            .sqsFactory(() -> sqs) //
            .messages() //
            .map(m -> m.message()) //
            .doOnError(Throwable::printStackTrace) //
            .take(2) //
            .test() //
            .awaitDone(10, TimeUnit.SECONDS) //
            .assertComplete() //
            .assertValues("body1", "body2");
    final InOrder inorder = Mockito.inOrder(sqs);
    inorder.verify(sqs, Mockito.atLeastOnce()).getQueueUrl(queueName);
    inorder.verify(sqs, Mockito.times(2)).receiveMessage(Mockito.<ReceiveMessageRequest>any());
    inorder.verify(sqs, Mockito.times(1)).shutdown();
    inorder.verifyNoMoreInteractions();
}
 
开发者ID:davidmoten,项目名称:rxjava2-aws,代码行数:25,代码来源:SqsTest.java

示例6: claimScanRangeTasks

import com.amazonaws.services.sqs.model.ReceiveMessageRequest; //导入依赖的package包/类
@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();
}
 
开发者ID:bazaarvoice,项目名称:emodb,代码行数:24,代码来源:SQSScanWorkflow.java

示例7: claimCompleteScanRanges

import com.amazonaws.services.sqs.model.ReceiveMessageRequest; //导入依赖的package包/类
@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();
}
 
开发者ID:bazaarvoice,项目名称:emodb,代码行数:20,代码来源:SQSScanWorkflow.java

示例8: testFirstCallToReceiveMessagesReturnsOneMessage

import com.amazonaws.services.sqs.model.ReceiveMessageRequest; //导入依赖的package包/类
@Test(timeout = 5000)
public void testFirstCallToReceiveMessagesReturnsOneMessage() {
	AmazonSQSClient sqs = Mockito.mock(AmazonSQSClient.class);
	String queueName = "queue";
	Mockito.when(sqs.getQueueUrl(queueName)).thenAnswer(x -> new GetQueueUrlResult().withQueueUrl(queueName));
	Mockito.when(sqs.receiveMessage(Mockito.<ReceiveMessageRequest>any()))
			.thenReturn(new ReceiveMessageResult().withMessages(new Message().withBody("body1")));
	Sqs.queueName(queueName) //
			.sqsFactory(() -> sqs) //
			.messages() //
			.map(m -> m.message()) //
			.doOnError(Throwable::printStackTrace) //
			.take(1) //
			.to(test()) //
			.awaitTerminalEvent() //
			.assertCompleted() //
			.assertValue("body1");
	InOrder inorder = Mockito.inOrder(sqs);
	inorder.verify(sqs, Mockito.atLeastOnce()).getQueueUrl(queueName);
	inorder.verify(sqs, Mockito.times(1)).receiveMessage(Mockito.<ReceiveMessageRequest>any());
	inorder.verify(sqs, Mockito.times(1)).shutdown();
	inorder.verifyNoMoreInteractions();
}
 
开发者ID:davidmoten,项目名称:rxjava-aws,代码行数:24,代码来源:SqsTest.java

示例9: testFirstCallToReceiveMessagesReturnsOneMessageAndHonoursBackpressure

import com.amazonaws.services.sqs.model.ReceiveMessageRequest; //导入依赖的package包/类
@Test(timeout = 5000)
public void testFirstCallToReceiveMessagesReturnsOneMessageAndHonoursBackpressure() {
	AmazonSQSClient sqs = Mockito.mock(AmazonSQSClient.class);
	String queueName = "queue";
	Mockito.when(sqs.getQueueUrl(queueName)).thenAnswer(x -> new GetQueueUrlResult().withQueueUrl(queueName));
	Mockito.when(sqs.receiveMessage(Mockito.<ReceiveMessageRequest>any()))
			.thenReturn(new ReceiveMessageResult().withMessages(new Message().withBody("body1")));
	Sqs.queueName(queueName) //
			.sqsFactory(() -> sqs) //
			.messages() //
			.map(m -> m.message()) //
			.doOnError(Throwable::printStackTrace) //
			.to(testWithRequest(0)) //
			.requestMore(1) //
			.assertValue("body1")//
			.assertNotCompleted() //
			.unsubscribe();
	InOrder inorder = Mockito.inOrder(sqs);
	inorder.verify(sqs, Mockito.atLeastOnce()).getQueueUrl(queueName);
	inorder.verify(sqs, Mockito.times(1)).receiveMessage(Mockito.<ReceiveMessageRequest>any());
	inorder.verify(sqs, Mockito.times(1)).shutdown();
	inorder.verifyNoMoreInteractions();
}
 
开发者ID:davidmoten,项目名称:rxjava-aws,代码行数:24,代码来源:SqsTest.java

示例10: testFirstCallToReceiveMessagesReturnsNoMessagesThenSecondCallReturnsTwoMessages

import com.amazonaws.services.sqs.model.ReceiveMessageRequest; //导入依赖的package包/类
@Test(timeout = 5000)
public void testFirstCallToReceiveMessagesReturnsNoMessagesThenSecondCallReturnsTwoMessages() {
	AmazonSQSClient sqs = Mockito.mock(AmazonSQSClient.class);
	String queueName = "queue";
	Mockito.when(sqs.getQueueUrl(queueName)).thenAnswer(x -> new GetQueueUrlResult().withQueueUrl(queueName));
	Mockito.when(sqs.receiveMessage(Mockito.<ReceiveMessageRequest>any())).thenReturn(new ReceiveMessageResult())
			.thenReturn(new ReceiveMessageResult().withMessages(new Message().withBody("body1"),
					new Message().withBody("body2")));
	Sqs.queueName(queueName) //
			.sqsFactory(() -> sqs) //
			.messages() //
			.map(m -> m.message()) //
			.doOnError(Throwable::printStackTrace) //
			.take(2) //
			.to(test()) //
			.awaitTerminalEvent() //
			.assertCompleted() //
			.assertValues("body1", "body2");
	InOrder inorder = Mockito.inOrder(sqs);
	inorder.verify(sqs, Mockito.atLeastOnce()).getQueueUrl(queueName);
	inorder.verify(sqs, Mockito.times(2)).receiveMessage(Mockito.<ReceiveMessageRequest>any());
	inorder.verify(sqs, Mockito.times(1)).shutdown();
	inorder.verifyNoMoreInteractions();
}
 
开发者ID:davidmoten,项目名称:rxjava-aws,代码行数:25,代码来源:SqsTest.java

示例11: receiveMessage

import com.amazonaws.services.sqs.model.ReceiveMessageRequest; //导入依赖的package包/类
@Override
public ReceiveMessageResult receiveMessage(ReceiveMessageRequest receiveMessageRequest) throws AmazonServiceException, AmazonClientException {
    Integer maxNumberOfMessages = receiveMessageRequest.getMaxNumberOfMessages() != null ? receiveMessageRequest.getMaxNumberOfMessages() : Integer.MAX_VALUE;
    ReceiveMessageResult result = new ReceiveMessageResult();
    Collection<Message> resultMessages = new ArrayList<Message>();
    
    synchronized (messages) {
        int fetchSize = 0;
        for (Iterator<Message> iterator = messages.iterator(); iterator.hasNext() && fetchSize < maxNumberOfMessages; fetchSize++) {
            Message rc = iterator.next();
            resultMessages.add(rc);
            iterator.remove();
            scheduleCancelInflight(receiveMessageRequest.getQueueUrl(), rc);
        }
    }
    
    result.setMessages(resultMessages);
    return result;
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:20,代码来源:AmazonSQSClientMock.java

示例12: pollMessageFromQueueByJobId

import com.amazonaws.services.sqs.model.ReceiveMessageRequest; //导入依赖的package包/类
public List<JobStatusNotification> pollMessageFromQueueByJobId(String queueUrl, String jobId) {
	ReceiveMessageRequest receiveMessageRequest = new ReceiveMessageRequest()
       .withQueueUrl(queueUrl)
       .withMaxNumberOfMessages(MAX_NUMBER_OF_MESSAGES)
       .withVisibilityTimeout(VISIBILITY_TIMEOUT)
       .withWaitTimeSeconds(WAIT_TIME_SECONDS);
			
	List<JobStatusNotification> jobStatusNotifications = new ArrayList<>();
	
	for (Message message : sqsClient.receiveMessage(receiveMessageRequest).getMessages()) {
		try {
			JobStatusNotification jobStatusNotification = parseMessage(message.getBody());
			
			if (jobStatusNotification.getJobId().equalsIgnoreCase(jobId)) {
				jobStatusNotifications.add(jobStatusNotification);
				sqsClient.deleteMessage(new DeleteMessageRequest().withQueueUrl(queueUrl).withReceiptHandle(message.getReceiptHandle()));
			}
		} catch (IOException e) {
			logger.error(e.getMessage(), e);
		}
	}		
	return jobStatusNotifications;		
}
 
开发者ID:TimShi,项目名称:s3_video,代码行数:24,代码来源:AWSAdapter.java

示例13: peekMessage

import com.amazonaws.services.sqs.model.ReceiveMessageRequest; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public T peekMessage(int waitFor) throws Exception {
       // Receive messages
	logger.info("Trying to recieve message from: " + _queueName);
       ReceiveMessageRequest receiveMessageRequest = new ReceiveMessageRequest(_queueURL);
       receiveMessageRequest.setMaxNumberOfMessages(1);
       receiveMessageRequest.setWaitTimeSeconds(waitFor);
       
       List<Message> messages = _sqs.receiveMessage(receiveMessageRequest).getMessages();
       
       for (Message message : messages) {
       	logger.info("  Got Message");
       	logger.info("    Body:          " + message.getBody());
       	logger.info("    Handle:        " + message.getReceiptHandle());
           
           _lastMessage = message;
           GenericMessage msg =  GenericMessage.fromXML(message.getBody());
   		if (!msg.type.equals(_msgClass.getName()))
   			throw new Exception("Invalid message type recieved.");
   		
           return (T) msg.body;
       }
	return null;
}
 
开发者ID:apelyos,项目名称:distributed-image-classification,代码行数:25,代码来源:Queue.java

示例14: messageShouldBeProcessedAfterBeingConsumed

import com.amazonaws.services.sqs.model.ReceiveMessageRequest; //导入依赖的package包/类
@Test
public void messageShouldBeProcessedAfterBeingConsumed() throws Exception {
    //GIVEN
    ReceiveMessageResult receiveMessageResult = new ReceiveMessageResult();
    Message message1 = new Message()
            .withMessageId("aaaa-bbbb-cccc-dddd-eeee")
            .withBody("Sample test message");
    Message message2 = new Message()
            .withMessageId("ffff-gggg-hhhh-iiii-jjjj")
            .withBody("Another sample test message");
    receiveMessageResult.setMessages(Lists.newArrayList(message1, message2));
    when(sqs.receiveMessage((ReceiveMessageRequest) anyObject())).thenReturn(receiveMessageResult, new ReceiveMessageResult());

    //WHEN
    receiverHandler.start();

    //THEN
    Thread.sleep(1000);
    verify(receiver, times(2)).receive(any());
    verify(receiver, times(1)).receive(message1);
    verify(receiver, times(1)).receive(message2);
}
 
开发者ID:sjarrin,项目名称:dropwizard-sqs-bundle,代码行数:23,代码来源:SqsReceiverHandlerTest.java

示例15: sendAndReceiveMessage

import com.amazonaws.services.sqs.model.ReceiveMessageRequest; //导入依赖的package包/类
@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));
}
 
开发者ID:bizo,项目名称:aws-java-sdk-stubs,代码行数:27,代码来源:AmazonSQSStubTest.java


注:本文中的com.amazonaws.services.sqs.model.ReceiveMessageRequest类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。