Spring AMQP 1.0 GA
SpringSource, a division of VMware, has released Spring AMQP 1.0 GA (1.0.0.RELEASE). The Spring AMQP project applies core Spring concepts to the development of AMQP-based messaging solutions, and is available in both Java and .NET versions. For a good primer on Spring AMQP and AMQP in general, read the "Introduction to SpringSource's Advanced Message Queuing Protocol Support".
Spring AMQP provides org.springframework.amqp.core.AmqpTemplate for sending and receiving messages. AMQP template implementations support sending and receiving POJOs instead of javax.jms.Message instances. They also provide a way to customize the MessageConverter used to marshal the Object. Spring + JMS users will notice similarities between JmsTemplate and the new AmqpTemplate.
Here are code snippets on how synchronous messaging works using Spring AMQP with RabbitMQ behind the scenes. RabbitMQ is a VMware product and is the default AMQP implementation used in the official Spring AMQP examples.
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:rabbit="http://www.springframework.org/schema/rabbit" xsi:schemaLocation="http://www.springframework.org/schema/rabbit http://www.springframework.org/schema/rabbit/spring-rabbit-1.0.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd"> <rabbit:connection-factory id="connectionFactory"/> <rabbit:template id="amqpTemplate" connection-factory="connectionFactory"/> <rabbit:admin connection-factory="connectionFactory"/> <rabbit:queue name="helloworld.queue"/> </beans>
The above spring configuration xml references the ConnectionFactory, creates a RabbitTemplate for access to the message broker, creates a RabbitAdmin to manage exchanges, queues and bindings, and finally creates the queue. Next are the Java code snippets to send and receive messages.
Producer.java import org.springframework.amqp.core.AmqpTemplate; ... AmqpTemplate amqpTemplate = context.getBean(AmqpTemplate.class); amqpTemplate.convertAndSend("helloworld.queue", "Hello World");
Consumer.java import org.springframework.amqp.core.AmqpTemplate; ... AmqpTemplate amqpTemplate = context.getBean(AmqpTemplate.class); System.out.println(amqpTemplate.receiveAndConvert("helloworld.queue"));
To get started, download the Spring AMQP for Java or the Spring AMQP for .NET. The Spring AMQP for Java artifacts are also available in the SpringSource Maven repository and Maven Central. Dependencies are spring-amqp, spring-core, spring-context. Include spring-rabbit if you are using RabbitMQ as the message broker. You can also try the Spring AMQP examples hosted at GitHub. The examples are Maven based projects and requires RabbitMQ and Erlang. Read the readme.md file that comes with the sample code for complete build instructions.
For Cloud Foundry users, VMware has also announced the free public beta of RabbitMQ on Cloud Foundry. You can use Spring AMQP to connect to RabbitMQ on Cloud Foundry, with examples to help you quickly get started. For Spring Integration users, AMQP support is available in version 2.1 M1.
Besides VMware's RabbitMQ, other AMQP based message-oriented middleware are Apache Qpid, Red Hat Enterprise MRG, and StormMQ (hosted). iMatrix's OpenAMQ is no longer supported and thus no longer an alternative.