Results 1 to 3 of 3

Thread: multicast/aggregate pattern in spring integration

  1. #1
    Join Date
    Feb 2010
    Posts
    15

    Default 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.

    thanks

  2. #2
    Join Date
    Jan 2008
    Location
    Mohnton, PA USA (that's near Philadelphia)
    Posts
    2,148

    Default

    That responsibility belongs to Message Dispatcher EIP pattern http://www.eaipatterns.com/MessageDispatcher.html 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:
    Code:
    <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:
    Code:
    <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 http://static.springsource.org/sprin...mplementations

    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:
    http://www.eaipatterns.com/MessageChannel.html
    http://www.eaipatterns.com/PointToPointChannel.html
    http://www.eaipatterns.com/PublishSubscribeChannel.html
    http://www.eaipatterns.com/DatatypeChannel.html
    http://www.eaipatterns.com/MessagingBridge.html
    etc. . .

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

  3. #3
    Join Date
    Jan 2008
    Location
    Mohnton, PA USA (that's near Philadelphia)
    Posts
    2,148

    Default

    Also, when Messages distributed across multiple message flows needs to be aggregated you obviously need an <aggregator>
    For example:
    Code:
    <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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •