本文整理汇总了Java中com.amazonaws.services.sqs.model.ReceiveMessageResult类的典型用法代码示例。如果您正苦于以下问题:Java ReceiveMessageResult类的具体用法?Java ReceiveMessageResult怎么用?Java ReceiveMessageResult使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ReceiveMessageResult类属于com.amazonaws.services.sqs.model包,在下文中一共展示了ReceiveMessageResult类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testPurgeQueue_shouldRemoveAll
import com.amazonaws.services.sqs.model.ReceiveMessageResult; //导入依赖的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");
}
示例2: testFirstCallToReceiveMessagesReturnsOneMessage
import com.amazonaws.services.sqs.model.ReceiveMessageResult; //导入依赖的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();
}
示例3: testFirstCallToReceiveMessagesReturnsOneMessageAndHonoursBackpressure
import com.amazonaws.services.sqs.model.ReceiveMessageResult; //导入依赖的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();
}
示例4: testFirstCallToReceiveMessagesReturnsNoMessagesThenSecondCallReturnsTwoMessages
import com.amazonaws.services.sqs.model.ReceiveMessageResult; //导入依赖的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();
}
示例5: getSpans
import com.amazonaws.services.sqs.model.ReceiveMessageResult; //导入依赖的package包/类
public List<Span> getSpans(boolean delete) {
Stream<Span> spans = Stream.empty();
ReceiveMessageResult result = client.receiveMessage(queueUrl);
while(result != null && result.getMessages().size() > 0) {
spans = Stream.concat(spans,
result.getMessages().stream().flatMap(AmazonSQSRule::decodeSpans)
);
result = client.receiveMessage(queueUrl);
if (delete) {
List<DeleteMessageRequest> deletes = result.getMessages().stream()
.map(m -> new DeleteMessageRequest(queueUrl, m.getReceiptHandle()))
.collect(Collectors.toList());
deletes.forEach(d -> client.deleteMessage(d));
}
}
return spans.collect(Collectors.toList());
}
示例6: testFirstCallToReceiveMessagesReturnsOneMessage
import com.amazonaws.services.sqs.model.ReceiveMessageResult; //导入依赖的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();
}
示例7: testFirstCallToReceiveMessagesReturnsOneMessageAndHonoursBackpressure
import com.amazonaws.services.sqs.model.ReceiveMessageResult; //导入依赖的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();
}
示例8: testFirstCallToReceiveMessagesReturnsNoMessagesThenSecondCallReturnsTwoMessages
import com.amazonaws.services.sqs.model.ReceiveMessageResult; //导入依赖的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();
}
示例9: receiveMessage
import com.amazonaws.services.sqs.model.ReceiveMessageResult; //导入依赖的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;
}
示例10: messageShouldBeProcessedAfterBeingConsumed
import com.amazonaws.services.sqs.model.ReceiveMessageResult; //导入依赖的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);
}
示例11: sendAndReceiveMessage
import com.amazonaws.services.sqs.model.ReceiveMessageResult; //导入依赖的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));
}
示例12: receive
import com.amazonaws.services.sqs.model.ReceiveMessageResult; //导入依赖的package包/类
@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;
}
示例13: receiveMessage_withoutTimeout_returnsTextMessage
import com.amazonaws.services.sqs.model.ReceiveMessageResult; //导入依赖的package包/类
@Test
public 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
assertNotNull(receivedMessage);
assertEquals("content", receivedMessage.getPayload());
}
示例14: receiveMessage_withSpecifiedTimeout_returnsTextMessage
import com.amazonaws.services.sqs.model.ReceiveMessageResult; //导入依赖的package包/类
@Test
public 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
assertNotNull(receivedMessage);
assertEquals("content", receivedMessage.getPayload());
}
示例15: receiveMessage_withSpecifiedTimeout_returnsNull
import com.amazonaws.services.sqs.model.ReceiveMessageResult; //导入依赖的package包/类
@Test
public 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
assertNull(receivedMessage);
}