简体   繁体   中英

Spring intgeration - recipientlistrouter - parallel processing

How does I can achieve parallel processing in spring-integration with recipient-list-router.

My goal is the router has to be content based and sending messages to various channel on parallel processing just like multicast. I tried multicast in Camel with camel-spring-integration but couldn't configure it for content based

Please help if something cane be done

Thanks

If I'm understanding the question right, you just need to use publish subscribe channels as the output channels of the router. The router will direct the message to the right pubsub channel based on content, then all handlers subscribed to that channel will be executed in parallel, assuming the output channel task executor is configured to have multiple threads.

<int:publish-subscribe-channel id="channel1" task-executor="someExecutor"/>
<int:publish-subscribe-channel id="channel2" task-executor="someExecutor"/>

<int:recipient-list-router id="customRouter" input-channel="routingChannel">
    <int:recipient channel="channel1" selector-expression="payload.equals('foo')"/>   
    <int:recipient channel="channel2" selector-expression="headers.containsKey('bar')"/>
</int:recipient-list-router>

The above recipient list router configuration is copied from section 5.1 of the Spring Integration reference manual.

I have achieved similar sort of requirements by extending the Spring-Integrations's RecipientListRouter as follows:

public class CententBasedRecipientListRouter extends RecipientListRouter {
    @Override
    protected void handleMessageInternal(final Message<?> message) {
       ......
    }
}

in overridden method, you can implement any customized content based routing logic as per your requirements.

This custom router can be configured as follows:

<bean id="customRecipientListRouter" class="CententBasedRecipientListRouter">
  <property name="channels">
    <list>
      <ref bean="parallelProcessingChannel1"/>
      <ref bean="parallelProcessingChannel2"/>
      <ref bean="parallelProcessingChannel3"/>
    </list>
  </property>
</bean>

<int:router ref="customRecipientListRouter" 
            input-channel="routingChannel"
            default-output-channel="errorChannel" />

In order to achieve Parallel Processing, you can have Task Executor channels as follows:

<int:channel id="parallelProcessingChannel1">
   <int:dispatcher task-executor="threadPoolExecutor"/>
</int:channel>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM