且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在多个线程中执行Spring集成流程以并行使用更多Amazon SQS队列消息?

更新时间:2023-11-25 13:23:28

要达到这样的要求,您可以使用ExecutorChannel而不是默认的DirectChannel.

To achiever such a requirements you can use an ExecutorChannel instead of default DirectChannel.

这样,所有的SQS消息都将被分发到ExecutorChannel提供的线程中,并因此并行执行.

This way all the SQS messages are going to be distributed to the the thread supplied by the ExecutorChannel and, therefore, performed in parallel.

有关ExecutorChannel的更多信息,请参见

More info about an ExecutorChannel is in the Reference Manual.

更新

所以,我的建议应该反映在您当前的配置中,例如:

So, what I suggest should be reflected in your current config like:

<int:channel id="channel_1">
   <int:dispatcher task-executor="someExecutor"/>
</int:channel>

更新

如果您仍然坚持拥有多个SQS适配器,则简化版本如下所示:

If you still insist to have several SQS Adapters, then simplified version is like this:

<int-aws:sqs-message-driven-channel-adapter
    sqs="sqsAsyncClient" 
    channel="sqs-to-metricator"
    queues="https://sqs.us-east-1.amazonaws.com/123/SomeSQSQueueName"
    max-number-of-messages="10"
    />


<int-aws:sqs-message-driven-channel-adapter
    sqs="sqsAsyncClient" 
    channel="sqs-to-metricator"
    queues="https://sqs.us-east-1.amazonaws.com/123/SomeSQSQueueName"
    max-number-of-messages="10"
    />

<int-aws:sqs-message-driven-channel-adapter
    sqs="sqsAsyncClient" 
    channel="sqs-to-metricator"
    queues="https://sqs.us-east-1.amazonaws.com/123/SomeSQSQueueName"
    max-number-of-messages="10"
    />

<int:channel id="sqs-to-metricator" />

<int:outbound-channel-adapter ref="restService"
    method="publish" channel="sqs-to-metricator" />

为了避免重复,您可以考虑切换到Java DSL并开始使用其ItengrationFlowContext进行动态IntegrationFlow注册:

Also to avoid duplication you can consider to switch to the Java DSL and start to use its ItengrationFlowContext for dynamic IntegrationFlow registrations: https://docs.spring.io/spring-integration/docs/5.0.4.RELEASE/reference/html/java-dsl.html#java-dsl-runtime-flows