本文整理汇总了Java中com.amazonaws.services.sqs.AmazonSQSAsync类的典型用法代码示例。如果您正苦于以下问题:Java AmazonSQSAsync类的具体用法?Java AmazonSQSAsync怎么用?Java AmazonSQSAsync使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
AmazonSQSAsync类属于com.amazonaws.services.sqs包,在下文中一共展示了AmazonSQSAsync类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: instantiation_WithCustomJacksonConverterThatSupportsJava8Types_shouldConvertMessageToString
import com.amazonaws.services.sqs.AmazonSQSAsync; //导入依赖的package包/类
@Test
public void instantiation_WithCustomJacksonConverterThatSupportsJava8Types_shouldConvertMessageToString() throws IOException {
// Arrange
AmazonSQSAsync amazonSqs = createAmazonSqs();
ObjectMapper objectMapper = Jackson2ObjectMapperBuilder.json().build();
MappingJackson2MessageConverter simpleMessageConverter = new MappingJackson2MessageConverter();
simpleMessageConverter.setSerializedPayloadClass(String.class);
simpleMessageConverter.setObjectMapper(objectMapper);
QueueMessagingTemplate queueMessagingTemplate = new QueueMessagingTemplate(amazonSqs, (ResourceIdResolver) null, simpleMessageConverter);
// Act
queueMessagingTemplate.convertAndSend("test", new TestPerson("Agim", "Emruli", LocalDate.of(2017, 1, 1)));
// Assert
ArgumentCaptor<SendMessageRequest> sendMessageRequestArgumentCaptor = ArgumentCaptor.forClass(SendMessageRequest.class);
verify(amazonSqs).sendMessage(sendMessageRequestArgumentCaptor.capture());
TestPerson testPerson = objectMapper.readValue(sendMessageRequestArgumentCaptor.getValue().getMessageBody(), TestPerson.class);
assertEquals("Agim", testPerson.getFirstName());
assertEquals("Emruli", testPerson.getLastName());
assertEquals(LocalDate.of(2017, 1, 1), testPerson.getActiveSince());
}
开发者ID:spring-cloud,项目名称:spring-cloud-aws,代码行数:27,代码来源:QueueMessagingTemplateTest.java
示例2: doDestroy_whenContainerCallsDestroy_DestroysDefaultTaskExecutor
import com.amazonaws.services.sqs.AmazonSQSAsync; //导入依赖的package包/类
@Test
public void doDestroy_whenContainerCallsDestroy_DestroysDefaultTaskExecutor() throws Exception {
// Arrange
SimpleMessageListenerContainer simpleMessageListenerContainer = new SimpleMessageListenerContainer();
AmazonSQSAsync sqs = mock(AmazonSQSAsync.class, withSettings().stubOnly());
simpleMessageListenerContainer.setAmazonSqs(sqs);
QueueMessageHandler messageHandler = mock(QueueMessageHandler.class);
simpleMessageListenerContainer.setMessageHandler(messageHandler);
simpleMessageListenerContainer.afterPropertiesSet();
simpleMessageListenerContainer.start();
// Act
simpleMessageListenerContainer.destroy();
// Assert
assertTrue(((ThreadPoolTaskExecutor) simpleMessageListenerContainer.getTaskExecutor()).getThreadPoolExecutor().isTerminated());
}
开发者ID:spring-cloud,项目名称:spring-cloud-aws,代码行数:18,代码来源:SimpleMessageListenerContainerTest.java
示例3: afterPropertiesSet_whenCalled_taskExecutorIsActive
import com.amazonaws.services.sqs.AmazonSQSAsync; //导入依赖的package包/类
@Test
public void afterPropertiesSet_whenCalled_taskExecutorIsActive() throws Exception {
// Arrange
SimpleMessageListenerContainer container = new SimpleMessageListenerContainer();
AmazonSQSAsync sqs = mock(AmazonSQSAsync.class, withSettings().stubOnly());
container.setAmazonSqs(sqs);
QueueMessageHandler messageHandler = mock(QueueMessageHandler.class);
container.setMessageHandler(messageHandler);
// Act
container.afterPropertiesSet();
// Assert
assertFalse(((ThreadPoolTaskExecutor) container.getTaskExecutor()).getThreadPoolExecutor().isTerminated());
container.stop();
}
开发者ID:spring-cloud,项目名称:spring-cloud-aws,代码行数:17,代码来源:SimpleMessageListenerContainerTest.java
示例4: testIsActive
import com.amazonaws.services.sqs.AmazonSQSAsync; //导入依赖的package包/类
@Test
public void testIsActive() throws Exception {
AbstractMessageListenerContainer container = new StubAbstractMessageListenerContainer();
AmazonSQSAsync mock = mock(AmazonSQSAsync.class, withSettings().stubOnly());
container.setAmazonSqs(mock);
container.setMessageHandler(mock(QueueMessageHandler.class));
container.afterPropertiesSet();
when(mock.getQueueUrl(new GetQueueUrlRequest().withQueueName("testQueue"))).
thenReturn(new GetQueueUrlResult().withQueueUrl("http://testQueue.amazonaws.com"));
container.start();
assertTrue(container.isRunning());
container.stop();
assertFalse(container.isRunning());
//Container can still be active an restarted later (e.g. paused for a while)
assertTrue(container.isActive());
}
开发者ID:spring-cloud,项目名称:spring-cloud-aws,代码行数:23,代码来源:MessageListenerContainerTest.java
示例5: sendMessage_validTextMessage_returnsTrue
import com.amazonaws.services.sqs.AmazonSQSAsync; //导入依赖的package包/类
@Test
public void sendMessage_validTextMessage_returnsTrue() throws Exception {
// Arrange
AmazonSQSAsync amazonSqs = mock(AmazonSQSAsync.class);
ArgumentCaptor<SendMessageRequest> sendMessageRequestArgumentCaptor = ArgumentCaptor.forClass(SendMessageRequest.class);
when(amazonSqs.sendMessage(sendMessageRequestArgumentCaptor.capture())).thenReturn(new SendMessageResult());
Message<String> stringMessage = MessageBuilder.withPayload("message content").build();
MessageChannel messageChannel = new QueueMessageChannel(amazonSqs, "http://testQueue");
// Act
boolean sent = messageChannel.send(stringMessage);
// Assert
verify(amazonSqs, only()).sendMessage(any(SendMessageRequest.class));
assertEquals("message content", sendMessageRequestArgumentCaptor.getValue().getMessageBody());
assertTrue(sent);
}
开发者ID:spring-cloud,项目名称:spring-cloud-aws,代码行数:19,代码来源:QueueMessageChannelTest.java
示例6: sendMessage_serviceThrowsError_throwsMessagingException
import com.amazonaws.services.sqs.AmazonSQSAsync; //导入依赖的package包/类
@Test
public void sendMessage_serviceThrowsError_throwsMessagingException() throws Exception {
//Arrange
AmazonSQSAsync amazonSqs = mock(AmazonSQSAsync.class);
Message<String> stringMessage = MessageBuilder.withPayload("message content").build();
MessageChannel messageChannel = new QueueMessageChannel(amazonSqs, "http://testQueue");
when(amazonSqs.sendMessage(new SendMessageRequest("http://testQueue", "message content").withDelaySeconds(0)
.withMessageAttributes(isNotNull()))).
thenThrow(new AmazonServiceException("wanted error"));
//Assert
this.expectedException.expect(MessagingException.class);
this.expectedException.expectMessage("wanted error");
//Act
messageChannel.send(stringMessage);
}
开发者ID:spring-cloud,项目名称:spring-cloud-aws,代码行数:19,代码来源:QueueMessageChannelTest.java
示例7: sendMessage_withMimeTypeAsStringHeader_shouldPassItAsMessageAttribute
import com.amazonaws.services.sqs.AmazonSQSAsync; //导入依赖的package包/类
@Test
public void sendMessage_withMimeTypeAsStringHeader_shouldPassItAsMessageAttribute() throws Exception {
// Arrange
AmazonSQSAsync amazonSqs = mock(AmazonSQSAsync.class);
QueueMessageChannel messageChannel = new QueueMessageChannel(amazonSqs, "http://testQueue");
String mimeTypeAsString = new MimeType("test", "plain", Charset.forName("UTF-8")).toString();
Message<String> message = MessageBuilder.withPayload("Hello").setHeader(MessageHeaders.CONTENT_TYPE, mimeTypeAsString).build();
ArgumentCaptor<SendMessageRequest> sendMessageRequestArgumentCaptor = ArgumentCaptor.forClass(SendMessageRequest.class);
when(amazonSqs.sendMessage(sendMessageRequestArgumentCaptor.capture())).thenReturn(new SendMessageResult());
// Act
boolean sent = messageChannel.send(message);
// Assert
assertTrue(sent);
assertEquals(mimeTypeAsString, sendMessageRequestArgumentCaptor.getValue().getMessageAttributes().get(MessageHeaders.CONTENT_TYPE).getStringValue());
}
开发者ID:spring-cloud,项目名称:spring-cloud-aws,代码行数:19,代码来源:QueueMessageChannelTest.java
示例8: sendMessage_withMimeTypeHeader_shouldPassItAsMessageAttribute
import com.amazonaws.services.sqs.AmazonSQSAsync; //导入依赖的package包/类
@Test
public void sendMessage_withMimeTypeHeader_shouldPassItAsMessageAttribute() throws Exception {
// Arrange
AmazonSQSAsync amazonSqs = mock(AmazonSQSAsync.class);
QueueMessageChannel messageChannel = new QueueMessageChannel(amazonSqs, "http://testQueue");
MimeType mimeType = new MimeType("test", "plain", Charset.forName("UTF-8"));
Message<String> message = MessageBuilder.withPayload("Hello").setHeader(MessageHeaders.CONTENT_TYPE, mimeType).build();
ArgumentCaptor<SendMessageRequest> sendMessageRequestArgumentCaptor = ArgumentCaptor.forClass(SendMessageRequest.class);
when(amazonSqs.sendMessage(sendMessageRequestArgumentCaptor.capture())).thenReturn(new SendMessageResult());
// Act
boolean sent = messageChannel.send(message);
// Assert
assertTrue(sent);
assertEquals(mimeType.toString(), sendMessageRequestArgumentCaptor.getValue().getMessageAttributes().get(MessageHeaders.CONTENT_TYPE).getStringValue());
}
开发者ID:spring-cloud,项目名称:spring-cloud-aws,代码行数:19,代码来源:QueueMessageChannelTest.java
示例9: receiveMessage_withoutTimeout_returnsTextMessage
import com.amazonaws.services.sqs.AmazonSQSAsync; //导入依赖的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());
}
开发者ID:spring-cloud,项目名称:spring-cloud-aws,代码行数:22,代码来源:QueueMessageChannelTest.java
示例10: receiveMessage_withSpecifiedTimeout_returnsTextMessage
import com.amazonaws.services.sqs.AmazonSQSAsync; //导入依赖的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());
}
开发者ID:spring-cloud,项目名称:spring-cloud-aws,代码行数:22,代码来源:QueueMessageChannelTest.java
示例11: receiveMessage_withSpecifiedTimeout_returnsNull
import com.amazonaws.services.sqs.AmazonSQSAsync; //导入依赖的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);
}
开发者ID:spring-cloud,项目名称:spring-cloud-aws,代码行数:21,代码来源:QueueMessageChannelTest.java
示例12: receiveMessage_withoutDefaultTimeout_returnsNull
import com.amazonaws.services.sqs.AmazonSQSAsync; //导入依赖的package包/类
@Test
public void receiveMessage_withoutDefaultTimeout_returnsNull() 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.emptyList()));
PollableChannel messageChannel = new QueueMessageChannel(amazonSqs, "http://testQueue");
//Act
Message<?> receivedMessage = messageChannel.receive(0);
//Assert
assertNull(receivedMessage);
}
开发者ID:spring-cloud,项目名称:spring-cloud-aws,代码行数:21,代码来源:QueueMessageChannelTest.java
示例13: receiveMessage_withMimeTypeMessageAttribute_shouldCopyToHeaders
import com.amazonaws.services.sqs.AmazonSQSAsync; //导入依赖的package包/类
@Test
public void receiveMessage_withMimeTypeMessageAttribute_shouldCopyToHeaders() throws Exception {
// Arrange
AmazonSQSAsync amazonSqs = mock(AmazonSQSAsync.class);
MimeType mimeType = new MimeType("test", "plain", Charset.forName("UTF-8"));
when(amazonSqs.receiveMessage(new ReceiveMessageRequest("http://testQueue").
withWaitTimeSeconds(0).
withMaxNumberOfMessages(1).
withAttributeNames(QueueMessageChannel.ATTRIBUTE_NAMES).
withMessageAttributeNames("All"))).
thenReturn(new ReceiveMessageResult().withMessages(new com.amazonaws.services.sqs.model.Message().withBody("Hello").
withMessageAttributes(Collections.singletonMap(MessageHeaders.CONTENT_TYPE,
new MessageAttributeValue().withDataType(MessageAttributeDataTypes.STRING).withStringValue(mimeType.toString())))));
PollableChannel messageChannel = new QueueMessageChannel(amazonSqs, "http://testQueue");
// Act
Message<?> receivedMessage = messageChannel.receive();
// Assert
assertEquals(mimeType, receivedMessage.getHeaders().get(MessageHeaders.CONTENT_TYPE));
}
开发者ID:spring-cloud,项目名称:spring-cloud-aws,代码行数:23,代码来源:QueueMessageChannelTest.java
示例14: sendMessage_withStringMessageHeader_shouldBeSentAsQueueMessageAttribute
import com.amazonaws.services.sqs.AmazonSQSAsync; //导入依赖的package包/类
@Test
public void sendMessage_withStringMessageHeader_shouldBeSentAsQueueMessageAttribute() throws Exception {
// Arrange
AmazonSQSAsync amazonSqs = mock(AmazonSQSAsync.class);
QueueMessageChannel messageChannel = new QueueMessageChannel(amazonSqs, "http://testQueue");
String headerValue = "Header value";
String headerName = "MyHeader";
Message<String> message = MessageBuilder.withPayload("Hello").setHeader(headerName, headerValue).build();
ArgumentCaptor<SendMessageRequest> sendMessageRequestArgumentCaptor = ArgumentCaptor.forClass(SendMessageRequest.class);
when(amazonSqs.sendMessage(sendMessageRequestArgumentCaptor.capture())).thenReturn(new SendMessageResult());
// Act
boolean sent = messageChannel.send(message);
// Assert
assertTrue(sent);
assertEquals(headerValue, sendMessageRequestArgumentCaptor.getValue().getMessageAttributes().get(headerName).getStringValue());
assertEquals(MessageAttributeDataTypes.STRING, sendMessageRequestArgumentCaptor.getValue().getMessageAttributes().get(headerName).getDataType());
}
开发者ID:spring-cloud,项目名称:spring-cloud-aws,代码行数:21,代码来源:QueueMessageChannelTest.java
示例15: instantiation_withDefaultMapping2JacksonConverter_shouldSupportJava8Types
import com.amazonaws.services.sqs.AmazonSQSAsync; //导入依赖的package包/类
@Test
public void instantiation_withDefaultMapping2JacksonConverter_shouldSupportJava8Types() throws IOException {
// Arrange
AmazonSQSAsync amazonSqs = createAmazonSqs();
ObjectMapper objectMapper = Jackson2ObjectMapperBuilder.json().build();
QueueMessagingTemplate queueMessagingTemplate = new QueueMessagingTemplate(amazonSqs);
// Act
queueMessagingTemplate.convertAndSend("test", new TestPerson("Agim", "Emruli", LocalDate.of(2017, 1, 1)));
// Assert
ArgumentCaptor<SendMessageRequest> sendMessageRequestArgumentCaptor = ArgumentCaptor.forClass(SendMessageRequest.class);
verify(amazonSqs).sendMessage(sendMessageRequestArgumentCaptor.capture());
TestPerson testPerson = objectMapper.readValue(sendMessageRequestArgumentCaptor.getValue().getMessageBody(), TestPerson.class);
assertEquals("Agim", testPerson.getFirstName());
assertEquals("Emruli", testPerson.getLastName());
assertEquals(LocalDate.of(2017, 1, 1), testPerson.getActiveSince());
}
开发者ID:spring-cloud,项目名称:spring-cloud-aws,代码行数:23,代码来源:QueueMessagingTemplateTest.java
示例16: receiveMessage_withIncompatibleNumericMessageHeader_shouldThrowAnException
import com.amazonaws.services.sqs.AmazonSQSAsync; //导入依赖的package包/类
@Test
public void receiveMessage_withIncompatibleNumericMessageHeader_shouldThrowAnException() throws Exception {
// Arrange
AmazonSQSAsync amazonSqs = mock(AmazonSQSAsync.class);
this.expectedException.expect(IllegalArgumentException.class);
this.expectedException.expectMessage("Cannot convert String [17] to target class [java.util.concurrent.atomic.AtomicInteger]");
HashMap<String, MessageAttributeValue> messageAttributes = new HashMap<>();
AtomicInteger atomicInteger = new AtomicInteger(17);
messageAttributes.put("atomicInteger", new MessageAttributeValue().withDataType(MessageAttributeDataTypes.NUMBER + ".java.util.concurrent.atomic.AtomicInteger").withStringValue(String.valueOf(atomicInteger)));
when(amazonSqs.receiveMessage(new ReceiveMessageRequest("http://testQueue").
withWaitTimeSeconds(0).
withMaxNumberOfMessages(1).
withAttributeNames(QueueMessageChannel.ATTRIBUTE_NAMES).
withMessageAttributeNames("All"))).
thenReturn(new ReceiveMessageResult().withMessages(new com.amazonaws.services.sqs.model.Message().withBody("Hello").
withMessageAttributes(messageAttributes)));
PollableChannel messageChannel = new QueueMessageChannel(amazonSqs, "http://testQueue");
// Act
messageChannel.receive();
}
开发者ID:spring-cloud,项目名称:spring-cloud-aws,代码行数:25,代码来源:QueueMessageChannelTest.java
示例17: receiveMessage_withMissingNumericMessageHeaderTargetClass_shouldThrowAnException
import com.amazonaws.services.sqs.AmazonSQSAsync; //导入依赖的package包/类
@Test
public void receiveMessage_withMissingNumericMessageHeaderTargetClass_shouldThrowAnException() throws Exception {
// Arrange
AmazonSQSAsync amazonSqs = mock(AmazonSQSAsync.class);
this.expectedException.expect(MessagingException.class);
this.expectedException.expectMessage("Message attribute with value '12' and data type 'Number.class.not.Found' could not be converted" +
" into a Number because target class was not found.");
HashMap<String, MessageAttributeValue> messageAttributes = new HashMap<>();
messageAttributes.put("classNotFound", new MessageAttributeValue().withDataType(MessageAttributeDataTypes.NUMBER + ".class.not.Found").withStringValue("12"));
when(amazonSqs.receiveMessage(new ReceiveMessageRequest("http://testQueue").
withWaitTimeSeconds(0).
withMaxNumberOfMessages(1).
withAttributeNames(QueueMessageChannel.ATTRIBUTE_NAMES).
withMessageAttributeNames("All"))).
thenReturn(new ReceiveMessageResult().withMessages(new com.amazonaws.services.sqs.model.Message().withBody("Hello").
withMessageAttributes(messageAttributes)));
PollableChannel messageChannel = new QueueMessageChannel(amazonSqs, "http://testQueue");
// Act
messageChannel.receive();
}
开发者ID:spring-cloud,项目名称:spring-cloud-aws,代码行数:25,代码来源:QueueMessageChannelTest.java
示例18: sendMessage_withBinaryMessageHeader_shouldBeSentAsBinaryMessageAttribute
import com.amazonaws.services.sqs.AmazonSQSAsync; //导入依赖的package包/类
@Test
public void sendMessage_withBinaryMessageHeader_shouldBeSentAsBinaryMessageAttribute() throws Exception {
// Arrange
AmazonSQSAsync amazonSqs = mock(AmazonSQSAsync.class);
QueueMessageChannel messageChannel = new QueueMessageChannel(amazonSqs, "http://testQueue");
ByteBuffer headerValue = ByteBuffer.wrap("My binary data!".getBytes());
String headerName = "MyHeader";
Message<String> message = MessageBuilder.withPayload("Hello").setHeader(headerName, headerValue).build();
ArgumentCaptor<SendMessageRequest> sendMessageRequestArgumentCaptor = ArgumentCaptor.forClass(SendMessageRequest.class);
when(amazonSqs.sendMessage(sendMessageRequestArgumentCaptor.capture())).thenReturn(new SendMessageResult());
// Act
boolean sent = messageChannel.send(message);
// Assert
assertTrue(sent);
assertEquals(headerValue, sendMessageRequestArgumentCaptor.getValue().getMessageAttributes().get(headerName).getBinaryValue());
assertEquals(MessageAttributeDataTypes.BINARY, sendMessageRequestArgumentCaptor.getValue().getMessageAttributes().get(headerName).getDataType());
}
开发者ID:spring-cloud,项目名称:spring-cloud-aws,代码行数:21,代码来源:QueueMessageChannelTest.java
示例19: receiveMessage_withBinaryMessageHeader_shouldBeReceivedAsByteBufferMessageAttribute
import com.amazonaws.services.sqs.AmazonSQSAsync; //导入依赖的package包/类
@Test
public void receiveMessage_withBinaryMessageHeader_shouldBeReceivedAsByteBufferMessageAttribute() throws Exception {
// Arrange
AmazonSQSAsync amazonSqs = mock(AmazonSQSAsync.class);
ByteBuffer headerValue = ByteBuffer.wrap("My binary data!".getBytes());
String headerName = "MyHeader";
when(amazonSqs.receiveMessage(new ReceiveMessageRequest("http://testQueue").
withWaitTimeSeconds(0).
withMaxNumberOfMessages(1).
withAttributeNames(QueueMessageChannel.ATTRIBUTE_NAMES).
withMessageAttributeNames("All"))).
thenReturn(new ReceiveMessageResult().withMessages(new com.amazonaws.services.sqs.model.Message().withBody("Hello").
withMessageAttributes(Collections.singletonMap(headerName,
new MessageAttributeValue().withDataType(MessageAttributeDataTypes.BINARY).withBinaryValue(headerValue)))));
PollableChannel messageChannel = new QueueMessageChannel(amazonSqs, "http://testQueue");
// Act
Message<?> receivedMessage = messageChannel.receive();
// Assert
assertEquals(headerValue, receivedMessage.getHeaders().get(headerName));
}
开发者ID:spring-cloud,项目名称:spring-cloud-aws,代码行数:24,代码来源:QueueMessageChannelTest.java
示例20: sendMessage_withUuidAsId_shouldConvertUuidToString
import com.amazonaws.services.sqs.AmazonSQSAsync; //导入依赖的package包/类
@Test
public void sendMessage_withUuidAsId_shouldConvertUuidToString() throws Exception {
// Arrange
AmazonSQSAsync amazonSqs = mock(AmazonSQSAsync.class);
QueueMessageChannel messageChannel = new QueueMessageChannel(amazonSqs, "http://testQueue");
Message<String> message = MessageBuilder.withPayload("Hello").build();
UUID uuid = (UUID) message.getHeaders().get(MessageHeaders.ID);
ArgumentCaptor<SendMessageRequest> sendMessageRequestArgumentCaptor = ArgumentCaptor.forClass(SendMessageRequest.class);
when(amazonSqs.sendMessage(sendMessageRequestArgumentCaptor.capture())).thenReturn(new SendMessageResult());
// Act
boolean sent = messageChannel.send(message);
// Assert
assertTrue(sent);
assertEquals(uuid.toString(), sendMessageRequestArgumentCaptor.getValue().getMessageAttributes().get(MessageHeaders.ID).getStringValue());
}
开发者ID:spring-cloud,项目名称:spring-cloud-aws,代码行数:19,代码来源:QueueMessageChannelTest.java
注:本文中的com.amazonaws.services.sqs.AmazonSQSAsync类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论