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

  • 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
    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

    Comment

    Working...
    X