AMQP, SQL Server, and XA

We are developing an application with the following characteristics:

  • standalone spring application 3.1.0.RELEASE
  • JPA with Hibernate 3.6.7. Final
  • AMQP (RabbitMQ as Server, spring AMQP as a client)
  • SQL Server 2008 with jTDS Driver

We need to synchronize transactions between RabbitMQ and SQL Server, so we are trying to configure XA with atomikos. The problem is that we cannot find one spring sample configuration file for this situation, which really works. We tried so many combinations using samples from spring documentation, google, forums, etc. Something is missing at all.

Can someone provide us with such a file so that we can use it as an initial template for our configuration.

PS Do we really need XA?

Thanks.

+8
amqp xa
source share
2 answers

After searching for various candidate solutions (using Change Data Capture adapters for SQL Server Service Broker and possible conversions from MSMQ to RabbitMQ), I came up with a solution that should work for you.

Turns out you can bind WCF clients and service contracts to SQL Server. From here, you can use the RabbitMQ AMQP binding for WCF to translate messages back and forth, as PDF documents are described in detail.

I don’t understand if an additional transaction manager, such as XA, is needed here, but if you have problems with transaction duplication, cycles and errors, it is worth exploring as an intermediary for connection. If you are following this route, you need to weld it in your gateway in the same way as you identified in the statement of problem. If this requires clarification, I would be happy to expand it here.

Best of luck with your application. It sounds like an integral hydra from the side, but as soon as you get everything you say together, it should work well.

+1
source share

As I know, RabbitMQ does not support XA type transactions.

And yes, you can do it in Java:

Testconfiguration.java

import org.springframework.amqp.core.Queue; import org.springframework.amqp.rabbit.config.AbstractRabbitConfiguration; import org.springframework.amqp.rabbit.connection.ConnectionFactory; import org.springframework.amqp.rabbit.connection.SingleConnectionFactory; import org.springframework.amqp.rabbit.core.RabbitTemplate; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @Configuration public class TestConfiguration extends AbstractRabbitConfiguration { private String routingKey = "test.queue"; private String testQueueName = "test.queue"; public ConnectionFactory getConnectionFactory() { SingleConnectionFactory connectionFactory = new SingleConnectionFactory("localhost"); connectionFactory.setUsername("guest"); connectionFactory.setPassword("guest"); return connectionFactory; } @Override public RabbitTemplate rabbitTemplate() { RabbitTemplate rabbitTemplate = new RabbitTemplate(getConnectionFactory()); rabbitTemplate.setRoutingKey(routingKey); rabbitTemplate.setQueue(testQueueName); return rabbitTemplate; 

A simple send example:

 import org.springframework.amqp.core.AmqpTemplate; import org.springframework.beans.factory.annotation.Autowired; public class MessageSender { @Autowired private AmqpTemplate template; public void send(String text) { template.convertAndSend(text); } } 

.. and get:

 import org.springframework.amqp.core.Message; import org.springframework.amqp.core.MessageListener; public class MessageHandler implements MessageListener { @Override public void onMessage(Message message) { System.out.println("Received message: " + message); } } 
0
source share

All Articles