How to rollback message taken from IBM MQ in spring integration

非 Y 不嫁゛ 提交于 2019-12-13 01:32:00

问题


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:


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.



来源:https://stackoverflow.com/questions/26590354/how-to-rollback-message-taken-from-ibm-mq-in-spring-integration

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!