Announcement Announcement Module
Collapse
No announcement yet.
Increasing the Transaction Boundaries in SpringIntegration. Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Increasing the Transaction Boundaries in SpringIntegration.

    Our Transaction Template is defined as follows:

    Tranaction Interceptor is defined as follows:

    Code:
            
     
            
            <bean abstract="true" id="grid.transactionTemplate" class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
                   <property name="interceptorNames">
                       <list>
                           <value>grid.transactionAdvisor</value>
                       </list>
                   </property>
               </bean>
           
           
                  <!-- Wrap that AOPed translation bean within a transaction framework -->
            <bean id="order.transactionProxyFactory" parent="grid.transactionTemplate">
                      <property name="beanNames">
                          <list>
                              <value>processorMap</value>
                          </list>
                      </property>
           </bean>
           
           
           
               <bean id="grid.transactionAdvisor" class="org.springframework.aop.support.DefaultPointcutAdvisor">
                   <property name="pointcut" ref="grid.gridPointCut"/>
                   <property name="advice" ref="grid.transactionInterceptor"/>
               </bean>
           
               <bean id="grid.gridPointCut" class="org.springframework.aop.support.NameMatchMethodPointcut">
                   <property name="mappedNames">
                       <list>
                           <value>invokeProcessor</value>
                       </list>
                       </property>
               </bean>
           
               <bean id="grid.transactionInterceptor"
                     class="org.springframework.transaction.interceptor.TransactionInterceptor">
                   <property name="transactionManager" ref="grid.transactionManager"/>
                   <property name="transactionAttributes">
                       <props>
                           <prop key="invokeProcessor">PROPAGATION_REQUIRED</prop>
                       </props>
                   </property>
               </bean>

    Our XML snippet is defined as follows which uses the above defined transaction template is as follows:

    h2. Transaction Usage

    Code:
    	
    	    <jms:message-driven-channel-adapter id="requestChannelAdapter"
    	                                        destination="requestTopic"
    	                                        connection-factory="topicConnectionFactory"
    	                                        message-converter="messageConverter"
                                            channel="request"/>
                                            
    	
                  <si:service-activator id="order"
                                 input-channel="request"
                                 ref="processorMap" method="invokeProcessor"
                                 output-channel="postProcessing"/>
                                 
                                 
      
    
           <bean id="processorMap" class="com.xx.MessageTypeProcessorMap">
    
          </bean>
        
        <si:router input-channel="postProcessing" ref="postProcessingRouter" method="route"/>
    
        <bean id="postProcessingRouter" class="com.xx.MessageTypeRouter">
            <property name="name" value="postProcessingRouter"/>
            <property name="destinations">
                <map>
                    <entry key="PRE_AMEND" value="prevalidation"/>
                </map>
            </property>
            <property name="defaultDestination" value="toSplit"/>
        </bean>
    
        <jms:outbound-channel-adapter id="prevalidationChannelAdapter"
                                      channel="prevalidation" jms-template="prevalidationJmsTemplate"/>
    
        <bean id="prevalidationJmsTemplate" class="org.springframework.jms.core.JmsTemplate">
            <property name="connectionFactory" ref="common.topicConnectionFactory"/>
            <property name="messageConverter" ref="order.messageConverter"/>
            <property name="defaultDestination" ref="common.prevalidationQueue"/>
        </bean>   
        
        
        <si:splitter input-channel="toSplit" output-channel="afterSplit" ref="splitter" method="split"/>
    
        <bean id="splitter" class="com.xx.Splitter"/>
    
        <si:router input-channel="afterSplit" ref="loopbackRouter" method="route"/>
    
        <bean id="loopbackRouter" class="com.xx.LoopbackRouter">
            <property name="name" value="loopbackRouter"/>
            <property name="destinations">
                <map>
                    <entry key="true" value="loopbackMessages"/>
                    <entry key="false" value="allQuerySplit"/> 
                </map>
            </property>
        </bean>
    
        <si:service-activator id="saLoopbackProcessor"
                              input-channel="loopbackMessages"
                              ref="loopbackProcessor"
                              method="processMessage"
                              output-channel="request"/>
    
        <bean id="order.loopbackProcessor" class="com.xx.LoopbackProcessor"/>
    
        <si:router input-channel="allQuerySplit" ref="allQueryRouter" method="route"/>
        <bean id="order.allQueryRouter" class="com.xx.MessageTypeRouter">
            <property name="name" value="postProcessingRouter"/>
            <property name="destinations">
                <map>
                    <entry key="ALL_STATE_QUERY" value="toFatQueries"/> 
                </map>
            </property>
            <property name="defaultDestination" value="broadcast"/>
        </bean>
        <jms:outbound-channel-adapter id="fatChannelAdapter"
                                      channel="toFatQueries" jms-template="allQueryJmsTemplate"/>
                                      
        <bean id="order.allQueryJmsTemplate" class="org.springframework.jms.core.JmsTemplate">
            <property name="connectionFactory" ref="common.topicConnectionFactory"/>
            <property name="messageConverter" ref="order.messageConverter"/>
            <property name="defaultDestination" ref="common.fatFillsQueue"/>
        </bean>
    
        <jms:outbound-channel-adapter id="broadcastChannelAdapter"
                                      channel="broadcast" jms-template="broadcastJmsTemplate"/>
    
        <bean id="broadcastJmsTemplate" class="org.springframework.jms.core.JmsTemplate">
            <property name="connectionFactory" ref="common.topicConnectionFactory"/>
            <property name="messageConverter" ref="messageConverter"/>
            <property name="defaultDestination" ref="common.broadcastTopic"/>
        </bean>
    
    
    </beans>

    As you can see the Transaction is bounded to invokeProcessor in service-activator with id="order . I want the Transaction to be started at serviceActivator
    and end only before it sends the message back to JmsTemplate / or increase the Transaction Boundaries. How can I achieve that when there are routers and
    splitters in between?

    Our Problem is our transaction is currently inside invokeProcessor alone. But there is also postProcessing going on after invokeProcessor method is done.
    We want the Transaction boundaries to extend until it sends the message back to JmsTemplate. Please suggest.

  • #2
    One possible solution -- Need suggestions on this approach.

    Whenever we are calling

    <si:service-activator id="order"
    input-channel="request"
    ref="processorMap" method="invokeProcessor"
    />

    We are getting channel injected into the processorMap and before invokeProcessor() is terminated, we are sending the message through the Channel retaining the Transaction since the Tx is PROPAGATION_REQUIRED.
    So, it commits only when the channel sends it through Router and Splitter and does it's stuff and then finally invokeProcessor() ends and tx is committed.

    Comment


    • #3
      You can set the transaction manager on the poller and several other places for exactly this reason. Be sure to avoid asynchronous hand-off inside your transaction boundaries.

      Comment

      Working...
      X