I have a Spring application that uses Hibernate and PostgreSQL. It also uses Spring AMQP (RabbitMQ).
I am using the Hibernate Transaction manager configured as follows:
<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager"
p:sessionFactory-ref="sessionFactory" p:dataSource-ref="dataSource" />
I'm using the SimpleMessageListenerContainer for asynchronous message reception configured as:
@Resource(name="transactionManager")
private PlatformTransactionManager txManager;
@Autowired
private MyListener messageListener;
@Bean
public SimpleMessageListenerContainer mySMLC()
{
final SimpleMessageListenerContainer container = new SimpleMessageListenerContainer();
container.setConnectionFactory(rabbitConnectionFactory);
container.setQueueNames("myQueue");
final MessageListenerAdapter adapter = new MessageListenerAdapter(messageListener);
adapter.setMessageConverter(converter);
container.setMessageListener(adapter);
container.setChannelTransacted(true);
container.setTransactionManager(txManager);
return container;
}
So basically I have specified that the reception of messages needs to be transactional. The message listener calls a service that can have methods annotated with @Transactional and possibly do CRUD operations on the DB.
My question is, is there a problem using the HibernateTransactionManager to manage the transaction at the SimpleMessageListenerContainer level? Will there be any issues using a DB transaction manager to wrap the receiving of messages from RabbitMQ?
I am not expecting XA here. I just want to ensure that if any operations on the DB by the service fails, the message does not get acked to the RabbitMQ broker.