Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ


Choose your language

InfoQ Homepage News Spring AMQP 1.0 GA

Spring AMQP 1.0 GA

This item in japanese

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=""

	<rabbit:connection-factory id="connectionFactory"/>
	<rabbit:template id="amqpTemplate" connection-factory="connectionFactory"/>
	<rabbit:admin connection-factory="connectionFactory"/>
	<rabbit:queue name="helloworld.queue"/>

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.

import org.springframework.amqp.core.AmqpTemplate;

AmqpTemplate amqpTemplate = context.getBean(AmqpTemplate.class);
amqpTemplate.convertAndSend("helloworld.queue", "Hello World");

import org.springframework.amqp.core.AmqpTemplate;

AmqpTemplate amqpTemplate = context.getBean(AmqpTemplate.class);

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

For more information on Spring AMQP, please visit the Spring AMQP Reference for Java and the Spring AMQP Reference for .NET reference pages.

Rate this Article