Spring AMQP / RabbitMQ and Hibernate Transaction Mananger

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 use SimpleMessageListenerContainer to receive messages asynchronously, 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 pointed out that receiving messages should be transactional. A message listener calls a service that can have methods annotated with @Transactional and possibly perform CRUD operations in the database.

: HibernateTransactionManager SimpleMessageListenerContainer? RabbitMQ?

XA. , , - , RabbitMQ.

+5
1

Spring MessageManagerContraner MessageListenerContainer , , , . , @Transactional, .

, , ack ​​ ( jms). XA . , , reset, . . , XA.

+1

All Articles