Template for saving an object, then a queue in RabbitMQ

I have a problem with RabbitMQ. I have a Notification class that I am trying to store in a database from a web service running under tomcat and then queue that object id to RabbitMQ for the consumer to pick up.

The problem is that the message is being queued before the transaction completes, so the consumer cannot find the record.

I tried to create a separate transaction for only the persistence part via Propagation.REQUIRES_NEW, but I got a Hibernate exception saying this:

org.hibernate.HibernateException: Illegally tried to bind a proxy with two open sessions

Is there a pattern for this that people usually do to solve this problem?

Any help is appreciated.

+3


source to share


1 answer


In response to your comment after mine; a simple solution would be to use the linked transaction manager as described in the Dave Syer JavaWorld article .



+1


source