BT

Spring AMQP 1.0 GA

by Bienvenido David on Sep 09, 2011 |

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.

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

Hello stranger!

You need to Register an InfoQ account or to post comments. But there's so much more behind being registered.

Get the most out of the InfoQ experience.

Tell us what you think

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread
Community comments

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Discuss

Educational Content

General Feedback
Bugs
Advertising
Editorial
InfoQ.com and all content copyright © 2006-2013 C4Media Inc. InfoQ.com hosted at Contegix, the best ISP we've ever worked with.
Privacy policy
BT