我正在寻找一个使用 Spring Integration + Amazon SQS 服务接收消息并将消息发送到队列的 Spring 应用程序的工作示例。
问问题
3181 次
1 回答
4
这是一个如何outbound channel adapter
使用 XML 配置的示例:
<int-aws:sqs-outbound-channel-adapter sqs="sqs"
auto-startup="false"
channel="errorChannel"
phase="100"
id="sqsOutboundChannelAdapter"
queue="foo"
delay-expression="'200'"
message-deduplication-id="foo"
message-group-id-expression="'bar'"
send-timeout="202"
sync="false"
error-message-strategy="errorMessageStrategy"
failure-channel="failureChannel"
success-channel="successChannel"
message-converter="messageConverter"
async-handler="asyncHandler"
resource-id-resolver="resourceIdResolver"/>
inbound channel adapter
看起来像这样:
<int-aws:sqs-message-driven-channel-adapter sqs="sqs"
auto-startup="false"
channel="errorChannel"
error-channel="nullChannel"
task-executor="taskExecutor"
phase="100"
id="sqsMessageDrivenChannelAdapter"
queues="foo, bar"
message-deletion-policy="NEVER"
max-number-of-messages="5"
visibility-timeout="200"
wait-time-out="40"
send-timeout="2000"
queue-stop-timeout="11000"
destination-resolver="destinationResolver"
resource-id-resolver="resourceIdResolver"/>
这是他们的Java变体:
@Bean
@ServiceActivator(inputChannel = "sqsSendChannelWithAutoCreate")
public MessageHandler sqsMessageHandlerWithAutoQueueCreate() {
DynamicQueueUrlDestinationResolver destinationResolver = new DynamicQueueUrlDestinationResolver(amazonSqs(), null);
destinationResolver.setAutoCreate(true);
return new SqsMessageHandler(amazonSqs(), destinationResolver);
}
@Bean
public MessageProducer sqsMessageDrivenChannelAdapter() {
SqsMessageDrivenChannelAdapter adapter = new SqsMessageDrivenChannelAdapter(amazonSqs(), "testQueue");
adapter.setOutputChannel(inputChannel());
return adapter;
}
您可以在项目的测试中找到更多示例:https ://github.com/spring-projects/spring-integration-aws/tree/master/src/test/java/org/springframework/integration/aws
于 2019-03-28T21:21:50.000 回答