本文整理汇总了Java中com.amazonaws.services.sqs.model.ReceiveMessageResult.setMessages方法的典型用法代码示例。如果您正苦于以下问题:Java ReceiveMessageResult.setMessages方法的具体用法?Java ReceiveMessageResult.setMessages怎么用?Java ReceiveMessageResult.setMessages使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.amazonaws.services.sqs.model.ReceiveMessageResult
的用法示例。
在下文中一共展示了ReceiveMessageResult.setMessages方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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;
}
示例2: 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);
}
示例3: incorrectMD5Test
import com.amazonaws.services.sqs.model.ReceiveMessageResult; //导入方法依赖的package包/类
@Test
public void incorrectMD5Test() throws MessageMarshallerException {
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(messageBody);
ReceiveMessageResult result = new ReceiveMessageResult();
result.setMessages(Collections.singletonList(sqsMessage));
when(mockSQS.receiveMessage(any(ReceiveMessageRequest.class)))
.thenReturn(result);
Message<?> recvMessage = executor.poll();
assertNull("No message since MD5 checksum failed", recvMessage);
}
示例4: correctMD5Test
import com.amazonaws.services.sqs.model.ReceiveMessageResult; //导入方法依赖的package包/类
@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);
}
示例5: testShouldFailWhileDeserializationOfFailedEvent
import com.amazonaws.services.sqs.model.ReceiveMessageResult; //导入方法依赖的package包/类
@Test
public void testShouldFailWhileDeserializationOfFailedEvent() {
final ReceiveMessageResult receiveMessageResult = new ReceiveMessageResult();
receiveMessageResult.setMessages(Collections.singleton(new Message()));
when(amazonSQS.receiveMessage(anyString())).thenReturn(receiveMessageResult);
assertThatThrownBy(() -> sqsFailedEventSource.getFailedEvent()).isInstanceOf(IllegalStateException.class)
.hasMessageContaining("Exception occurred during deserialization. Message id =");
}
示例6: testShouldFetchFailedEventFromSQS
import com.amazonaws.services.sqs.model.ReceiveMessageResult; //导入方法依赖的package包/类
@Test
public void testShouldFetchFailedEventFromSQS() throws JsonProcessingException {
final FailedEvent failedEvent = new FailedEvent();
failedEvent.setRawEvent(randomAlphabetic(10));
failedEvent.setOffset(randomAlphabetic(10));
failedEvent.setConsumerName(randomAlphabetic(10));
failedEvent.setFailedTimeInMilliSeconds(nextLong(1, 10));
failedEvent.setEventType(new EventType(randomAlphabetic(10)));
failedEvent.setPartition(randomAlphabetic(10));
failedEvent.setStackTrace(randomAlphabetic(10));
final Message message = new Message();
message.setMessageId(randomAlphabetic(10));
message.setReceiptHandle(randomAlphabetic(10));
message.setBody(objectMapper.writeValueAsString(failedEvent));
final ReceiveMessageResult receiveMessageResult = new ReceiveMessageResult();
receiveMessageResult.setMessages(Collections.singleton(message));
when(amazonSQS.receiveMessage(anyString())).thenReturn(receiveMessageResult);
final Optional<SQSFailedEvent> sqsFailedEventOptional = sqsFailedEventSource.getFailedEvent();
assertThat(sqsFailedEventOptional).isPresent();
final SQSFailedEvent sqsFailedEvent = sqsFailedEventOptional.get();
assertThat(sqsFailedEvent.getRawEvent()).isEqualTo(failedEvent.getRawEvent());
assertThat(sqsFailedEvent.getReceiptHandle()).isEqualTo(message.getReceiptHandle());
assertThat(sqsFailedEvent.getConsumerName()).isEqualTo(failedEvent.getConsumerName());
assertThat(sqsFailedEvent.getEventType()).isEqualTo(failedEvent.getEventType());
assertThat(sqsFailedEvent.getId()).isEqualTo(message.getMessageId());
assertThat(sqsFailedEvent.getOffset()).isEqualTo(failedEvent.getOffset());
assertThat(sqsFailedEvent.getPartition()).isEqualTo(failedEvent.getPartition());
assertThat(sqsFailedEvent.getStackTrace()).isEqualTo(failedEvent.getStackTrace());
assertThat(sqsFailedEvent.getFailedTimeInMilliSeconds()).isEqualTo(failedEvent.getFailedTimeInMilliSeconds());
}
示例7: testShouldIgnoreUnknownFields
import com.amazonaws.services.sqs.model.ReceiveMessageResult; //导入方法依赖的package包/类
@Test
public void testShouldIgnoreUnknownFields() throws Exception {
final Message message = new Message();
message.setBody("{\"unknown_field\": 1}");
final ReceiveMessageResult receiveMessageResult = new ReceiveMessageResult();
receiveMessageResult.setMessages(Collections.singleton(message));
when(amazonSQS.receiveMessage(anyString())).thenReturn(receiveMessageResult);
final Optional<SQSFailedEvent> sqsFailedEventOptional = sqsFailedEventSource.getFailedEvent();
assertThat(sqsFailedEventOptional).isPresent();
}
示例8: messageShouldBeDeletedAfterBeingConsumed
import com.amazonaws.services.sqs.model.ReceiveMessageResult; //导入方法依赖的package包/类
@Test
public void messageShouldBeDeletedAfterBeingConsumed() throws Exception {
//GIVEN
ReceiveMessageResult receiveMessageResult = new ReceiveMessageResult();
Message message1 = new Message()
.withMessageId("aaaa-bbbb-cccc-dddd-eeee")
.withBody("Sample test message")
.withReceiptHandle("qwertz");
Message message2 = new Message()
.withMessageId("ffff-gggg-hhhh-iiii-jjjj")
.withBody("Another sample test message")
.withReceiptHandle("asdfgh");
receiveMessageResult.setMessages(Lists.newArrayList(message1, message2));
// simulate at the 2nd call that the message has been deleted on SQS side
when(sqs.receiveMessage((ReceiveMessageRequest) anyObject()))
.thenReturn(receiveMessageResult)
.thenReturn(new ReceiveMessageResult());
DeleteMessageRequest deleteMessageRequest = new DeleteMessageRequest(queueUrl, "asdfgh");
doNothing().when(sqs).deleteMessage(deleteMessageRequest);
//WHEN
receiverHandler.start();
//THEN
Thread.sleep(100);
verify(sqs, times(1)).deleteMessage(deleteMessageRequest);
}