Results 1 to 3 of 3

Thread: Wrapping a handler chain in Transaction.

  1. #1
    Join Date
    Jul 2009
    Posts
    7

    Default 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"/>
    ........
    </chain>.

    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. #2
    Join Date
    Mar 2010
    Location
    Gtr Philadelphia, PA
    Posts
    2,017

    Default

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

    Code:
    public interface TransactionalGateway {
    
    	@Transactional
    	public MyResponseType sendInTx(MyRequestType requestPayload);
    }
    Code:
    <!-- Start a database transaction NOW -->
    <int:service-activator input-channel="my.inbound"
    				       ref="inbound.tx.gateway" method="sendInTx"/>
    	
    <int:gateway id="inbound.tx.gateway" 
            service-interface="my.package.TransactionalGateway"
    	default-request-channel="my.tx.inbound"/>
    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.
    Gary P. Russell
    Spring Integration Team
    SpringSource, a division of VMware

  3. #3
    Join Date
    Jul 2009
    Posts
    7

    Default

    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.

Tags for this Thread

Posting Permissions

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