Results 1 to 2 of 2

Thread: AMQP, SQL Server and XA

  1. #1
    Join Date
    Apr 2008
    Posts
    22

    Default AMQP, SQL Server and XA

    Hi,
    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.

    P.S.
    Do we really need XA?

    Thanks.

  2. #2

    Default

    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:
    Code:
    <!-- JpaTransactionManager -->
    <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager" />
    
    <!-- RabbitTemplate -->
    <rabbit:template id="amqpTemplate" 
        connection-factory="connectionFactory" 
        channel-transacted="true" /> 
    
    <!-- SimpleMessageListenerContainer -->
    <rabbit:listener-container connection-factory="connectionFactory" transaction-manager="transactionManager" >
        <rabbit:listener queues="some.queue" ref="messageHandler" method="handle"/>
    </rabbit:listener-container>
    Your code:
    Code:
    ......
        @PersistenceContext
        private EntityManager em;
    	
        @Inject
        private AmqpTemplate amqpTemplate;
    	
        
        @Transactional
        public void insertRowAndSendMessage() {
            //entity
    	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 (http://static.springsource.org/sprin...e/html/#d0e734)


    nicolas.loriente

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •