Announcement Announcement Module
Collapse
No announcement yet.
@after-returning advice executes before transaction is committed Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • @after-returning advice executes before transaction is committed

    We are using spring 2.5 with jms (no jms transactions) and spring-jdbc with <tx:annotation-driven/>.

    We have a MessageListener which is annotated with @Transactional to support transactions a the top level. When the onMessage() returns (or actually when the transaction has bee committed) we want to do "stuff".

    Our problem is that the advice is called when the onMessage() method returns but before the transaction proxy has committed the transactions.

    I guess is that somehow we want our proxy "outside" or "before" the transactional behaviour but I am not sure how to solve this. I have gone through previous posts which suggests pre/post interceptors with the TransactionProxyFactoryBean but this seems to be the approach when NOT using annotations.

    Advice config.

    <aop:aspect ref="ourAdvice">
    <aop:after-returning
    pointcut="execution(public * our.package.common.TransactionalMessageListenerAda pter.onMessage(..))"
    method="doSomething" />
    </aop:aspect>


    MessageListener

    @Transactional
    public class TransactionalMessageListenerAdapter extends MessageListenerAdapter {

    private MessageFilter messageFilter = null;

    public void setMessageFilter(MessageFilter messageFilter) {
    this.messageFilter = messageFilter;
    }

    @Override
    @Transactional(propagation = Propagation.REQUIRED)
    public void onMessage(Message message, Session session) throws JMSException {
    if(messageFilter != null && !messageFilter.accept(message)) {
    return;
    }
    super.onMessage(message, session);
    }

    @Override
    @Transactional(propagation = Propagation.REQUIRED)
    public void onMessage(Message message) {
    super.onMessage(message);
    }
    }
    Last edited by johras; Apr 7th, 2008, 05:18 AM.

  • #2
    Originally posted by johras View Post
    We are using spring 2.5 with jms (no jms transactions) and spring-jdbc with <tx:annotation-driven/>.

    We have a MessageListener which is annotated with @Transactional to support transactions a the top level. When the onMessage() returns (or actually when the transaction has bee committed) we want to do "stuff".

    Our problem is that the advice is called when the onMessage() method returns but before the transaction proxy has committed the transactions.

    I guess is that somehow we want our proxy "outside" or "before" the transactional behaviour but I am not sure how to solve this. I have gone through previous posts which suggests pre/post interceptors with the TransactionProxyFactoryBean but this seems to be the approach when NOT using annotations.

    Advice config.

    <aop:aspect ref="ourAdvice">
    <aop:after-returning
    pointcut="execution(public * our.package.common.TransactionalMessageListenerAda pter.onMessage(..))"
    method="doSomething" />
    </aop:aspect>


    MessageListener

    @Transactional
    public class TransactionalMessageListenerAdapter extends MessageListenerAdapter {

    private MessageFilter messageFilter = null;

    public void setMessageFilter(MessageFilter messageFilter) {
    this.messageFilter = messageFilter;
    }

    @Override
    @Transactional(propagation = Propagation.REQUIRED)
    public void onMessage(Message message, Session session) throws JMSException {
    if(messageFilter != null && !messageFilter.accept(message)) {
    return;
    }
    super.onMessage(message, session);
    }

    @Override
    @Transactional(propagation = Propagation.REQUIRED)
    public void onMessage(Message message) {
    super.onMessage(message);
    }
    }
    I think you need to set proper order of advices.
    Try to set
    Code:
    <tx:annotation-driven order="2000"/>
    and then set attribute order on aop:aspect element (you need to check schema) to value less then 2000.

    Iw will set order of advices on your pointcut

    Comment


    • #3
      Thanks a lot for the tip, works like a charm!
      Im gonna dig into this order stuff a little bit...

      Comment

      Working...
      X