Results 1 to 2 of 2

Thread: Transaction + Router.

  1. #1

    Question Transaction + Router.

    We have a transaction that we would like to propagate across chain of events.
    In this chain of events is a router, which might have multiple destinations.
    Whenever the router routes the message across multiple channels the transaction is stopped and the threads are spawned by the router to move forward.

    But, what we want is to follow the same set of events in a linear progression like a chain so as to retain the existing transaction(by removing /using the router if possible). How is it possible? or Is it possible at all?

    Currently, we have the following code:

    Code:
       Transaction starts above....
       
       next comes the router.. Plan is not to start/spawn any threads by the router. Complete a single flow then start another flow and so on and so forth in
       a linear progression.
       
       Subsequent channel Router sends the message to should use the same message. 
    
        <si:router id="RouteMessages" input-channel="forRouting"
               ref="MessageRouter" method="route"/>
    
        <bean id="MessageRouter" class="xx.MessageRouter">
            <constructor-arg value="toRequest"/>
            <constructor-arg value="toProcess"/>
        </bean>
    
        <si:service-activator id="saProcessor"
                              input-channel="toProcess" output-channel="toSplit"
                              ref="messageTypeProcessor" method="service">
            <si:poller receive-timeout="300000">
                <si:interval-trigger interval="1"/>
            </si:poller>
        </si:service-activator>
        
        <jms:outbound-channel-adapter id="requestTopicSender"
                                      channel="toRequest" jms-template="outboundRequestTopicJmsTemplate"/>
    Last edited by srikanthradix; Apr 6th, 2010 at 01:07 PM.

  2. #2
    Join Date
    Oct 2008
    Location
    Poland, Wrocław
    Posts
    429

    Default

    Hi

    Generally (and also according to JEE spec) transactions are entities tightly connected with threads. The implementation aspect of this fact is that transaction objects (whatever they are) are held in ThreadLocal variables.

    So if you want to use both transactions and asynchronous processing (which you use by explicitly using poller) you have to re-think your application's transaction demarcation.

    I had the same problem - one thread had to periodically load some objects from database and then these object were to be processed by different service-activators (the dispatching was performed by router). My solution was to split the transactions - first, read-only transaction was used to load the objects initially and then, second transaction was started by the poller after dispatching the event by the router. So your solution should be to add <int:transactional /> to <int:poller /> declaration.

    regards
    Grzegorz Grzybek

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
  •