Announcement Announcement Module
No announcement yet.
Wrapping a handler chain in Transaction. Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Wrapping a handler chain in Transaction.

    How do you wrap a transaction around the invocation of a handler chain. I have a handler chain that is something like this

    <chain input-channel="FRA">
    <service-activator ref="tradeGroupFpmlMapper"/>
    <service-activator ref="tradeFpmlMapper"/>

    I would like Spring to start a transaction before invoking the first Service Activator and commit the transaction at the end of the chain of the service activators.

    What is the easiest way to do this (I am guessing an interceptor but not sure how to configure one without having to write something on my own).

  • #2
    It depends; if you are invoking the SI flow from Java, simply start the transaction before invoking the flow.

    If you are using external integration (e.g. inbound http gateway), or you want to start the transaction further down the flow, simply introduce a transactional gateway into your flow...

    public interface TransactionalGateway {
    	public MyResponseType sendInTx(MyRequestType requestPayload);
    <!-- Start a database transaction NOW -->
    <int:service-activator input-channel="my.inbound"
    				       ref="inbound.tx.gateway" method="sendInTx"/>
    <int:gateway id="inbound.tx.gateway" 
    If your downstream flow doesn't return a response, just return void in the Tx Gateway.

    This will only work with downstream direct channels. Also, if you add an error-channel on the gateway (which works like a catch block), and you don't thrown an exception from the error flow, the transaction will be committed.


    • #3
      Thanks Gary. That helps. I ended up choosing the second approach. And everything after the gateway is a direct channel so in the context of the same thread.