Announcement Announcement Module
No announcement yet.
Transactional publishing of event messages doable in Spring Integration? Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Transactional publishing of event messages doable in Spring Integration?


    I'm investigating Spring Integration because I need some lightweight (asynch of course) event dispatching mechanism to multiple subscribers, that would be transactional, both on publish and subscribe side.
    Meaning, when publisher puts event message on pub-sub channel, I don't want it to be received by subscribers until publish invoking transaction has been committed.
    Also on subscriber side - I don't want event message to be removed from channel (for each subscriber), until the subscriber has not consumed the event in successful transaction.

    Is this possible to implement in Spring Integration?

    Until now, I have checked if transactional publishing works, but it seemed it does not with typical configuration like following:

        <int:gateway id="myEventPublisher" service-interface="" default-request-channel="eventChannel"/>
        <int:publish-subscribe-channel id="eventChannel" task-executor="eventDispatchingTaskExecutor"/>
        <task:executor id="eventDispatchingTaskExecutor" pool-size="10"/>
        <int:service-activator ref="myEventSubscriber" method="handleMyEvent" input-channel="eventChannel" />
        <bean id="myEventSubscriber" class="my.comapany.MyEventSubscriber"/>
    After I published the event, I threw the exception causing the transaction on publishing side to rollback, but unfortunately, the subscriber still received the event :-(

    Any help with this, or Spring Integration is not capable of providing what is needed.

    Last edited by vmarcinko; Aug 7th, 2012, 04:11 AM.

  • #2
    The simple <publish-subscribe-channel> is not transactional, but it can easily be swapped for an alternate version that is backed by a transactional resource, such as a JMS provider or RabbitMQ. In both cases, it's just matter of using the corresponding namespace, e.g. the "amqp" namespace also provides a pub-sub channel element: <publish-subscribe-channel id="myRabbitPubSubChannel"/>

    Alternatively, depending on how your application is structured, you may use channel-adapters instead. Those are at the inbound and/or outbound "edge" of the application, so that you can modularize your application, e.g.

    app1's rabbit outbound-channel-adapter -> app 2's rabbit inbound-channel-adapter

    Finally, we also provide a point-to-point channel that is backed by a <queue> that can in turn use any pluggable Message Store (e.g. JDBC, GemFire, MongoDB, Redis, ...). Depending on the behavior you need, it is possible to bridge the consuming side of that point-to-point channel so that is simply passes messages directly along to a publish-subscribe-channel.

    Hopefully that gives you a few ideas. You can learn more about these options in the reference manual: