Announcement Announcement Module
No announcement yet.
multicast/aggregate pattern in spring integration Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • multicast/aggregate pattern in spring integration

    Hi, I'm just wondering how do I do a multicast of a message to difference service points in parallel and gather responses from each of the end point to aggregate them together. I know in camel they have multicast but I don't see anything similar in spring integration.


  • #2
    That responsibility belongs to Message Dispatcher EIP pattern which allows multiple consumers to the same channel to receive messages in paralel. In SpringIntegration we have BroadcastingMessageDispatcher which is injected automatically into PublishSubscribeChannel, while also exposing few configuration attributes.
    While the above may sound a bit complicated it really isn't in practice. Just look at this configuration:
    <int:publish-subscribe-channel id="myPubSubChannel"/>
    <int:service-activator id="serviceA" input-channel="myPubSubChannel" . . ./>
    <int:service-activator id="serviceB" input-channel="myPubSubChannel" . . ./>
    <int:service-activator id="serviceC" input-channel="myPubSubChannel" . . ./>
    In the above the Message sent to 'myPubSubChannel' wil be distributed to all services. However by default it will be done synchronously. If you want the distribution to be asynchronous you should tell MessageDispatcher attached to the PublishSubscribeChannel which TaskExecutor to use.
    For example:
    <task:executor id="myExecutor" pool-size="10"/>
    <int:publish-subscribe-channel id="myPubSubChannel"  task-executor="myExecutor"/>
    You can read up more on the Spring Integration Message Channels here

    Also, I'd suggest to read up on various Message Channel definitions from EIP. You'll find SI to be very much aligned with it (unlike Camel which does not provide implementation for Channels) and it will make it easier for you to understand more advanced topics:
    etc. . .

    You'll find an equivalent implementation of these channes in SI.


    • #3
      Also, when Messages distributed across multiple message flows needs to be aggregated you obviously need an <aggregator>
      For example:
      <int:publish-subscribe-channel id="myPubSubChannel" apply-sequence="true"/>
      <int:service-activator id="serviceA" input-channel="myPubSubChannel" output-channel="aggregatingChannel"/>
      <int:service-activator id="serviceB" input-channel="myPubSubChannel" output-channel="aggregatingChannel"/>
      <int:service-activator id="serviceC" input-channel="myPubSubChannel" output-channel="aggregatingChannel"/>
      <int:aggregator input-channel="aggregatingChannel"/>
      In the above the 'aggregatingChannel' will be automatically created as a DirectChannel (you can always define it explicitly if you want)
      The aggregato configuration is really that simple (as you see above) for this default scenario since by adding apply-sequence="true" on the publish-subscribe-channel we ensured that all the Message Headers required by the aggregator to perform default aggregation are there.