Announcement Announcement Module
No announcement yet.
AMQP, SQL Server and XA Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • AMQP, SQL Server and XA

    we are developing an application with following characteristics:
    • standalone spring 3.1.0.RELEASE application
    • JPA with Hibernate 3.6.7.Final
    • AMQP (RabbitMQ as Server, Spring AMQP as Client)
    • SQL Server 2008 with jTDS driver

    We need to synchronize transactions between RabbitMQ and SQL Server, so we are trying to setup XA with atomikos. The problem is that we canīt find a single spring sample configuration file for that situation that actually works. We tried so many combinations using samples from Spring documentation, google, forums, etc. Something is allways missing.

    Could someone, please, provide us a such file so we can use it as a starting template for our configuration.

    Do we really need XA?


  • #2
    To synchronize RabbitMQ and SQL Server within a external client transaction:
    1. configure a PlatformTransactionManager
    2. set the "channelTransacted" flag to true in the RabbitTemplate and/or provide the "transactionManager" to the SimpleMessageListenerContainer.

    Spring conf:
    <!-- JpaTransactionManager -->
    <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager" />
    <!-- RabbitTemplate -->
    <rabbit:template id="amqpTemplate" 
        channel-transacted="true" /> 
    <!-- SimpleMessageListenerContainer -->
    <rabbit:listener-container connection-factory="connectionFactory" transaction-manager="transactionManager" >
        <rabbit:listener queues="some.queue" ref="messageHandler" method="handle"/>
    Your code:
        private EntityManager em;
        private AmqpTemplate amqpTemplate;
        public void insertRowAndSendMessage() {
    	User user = new User();
    	user.setFirstName( "nicolas" );
    	user.setLastName( "loriente" );
            em.persist( user ); // database operation
            amqpTemplate.convertAndSend( "some.queue", user ); // amqp broker operation
    I'm omitting service and repository classes for simplicity but the example above is fully functional and will get your transaction synchronization.

    You can read about it on the Transactions section of the Spring AMQP Reference Documentation (