1

I have a spring integration flow like this:

    1) message-driven-channel-adapter -> 
                 1.1) output-channel connected to -> service-activator -> outbound-channel-adapter (for sending response)
                 1.2) error-channel connected to -> exception-type-router 
                            1.2.1) message is sent to different queues depending on the exception type using outbound-channel-adapter

I have set acknowledge="transacted" in message-driven-channel-adapter. I want to introduce rollback for a specific type of exception, after error-channel.

First, I tried to connect the exception-type-router output to service-activator. But i get exception:

   Code: 

     <service-activator id="rollBackActivator" input-channel="RollBackChannel" 
             ref="errorTransformer" method="rollBackMessage"/>

     public void rollBackMessage(MessagingException  message){       
         TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
     System.out.println("Message rolled back:"+TransactionAspectSupport.currentTransactionStatus().isRollbackOnly());
 }

   Exception:
   org.springframework.messaging.MessageHandlingException: org.springframework.transaction.NoTransactionException: No transaction aspect-managed TransactionStatus in scope

Then, I tried with outbound-channel-adapter expression , But got another exception again

Code:
<outbound-channel-adapter id="rollbackOut" channel="RollBackChannel" 
     expression="T(org.springframework.transaction.interceptor.TransactionAspectSupport).currentTransactionStatus().setRollbackOnly()"/>

 Exception:
 org.springframework.messaging.MessageHandlingException: Expression evaluation failed: T(org.springframework.transaction.interceptor.TransactionAspectSupport).currentTransactionStatus().setRollbackOnly()

Please advise to implement rollback in this scenario.

1 Answer 1

0

The container uses local transactions on the session by default. There's no AOP involved. Simply throw an exception and the container will roll back the message.

1
  • Thanks Gary.Am able to roll back the message by throwing exception.
    – Vidya_85
    Oct 31, 2014 at 9:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.