當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。