Today I have the immense pleasure of announcing the launch of the OpenCredo AMQ project. From the project announcement page:
"The goal of OpenCredo AMQ project is to facilitate communication between Java applications and AMQ servers (brokers)."
Headed up by OpenCredo founder Jonas Partner, our team have developed the following key features in this first version of the code:
- AmqTemplate - This template, in the style of Spring's Template approach (JDBCTemplate for example), simplifies the use of AMQ from Java.
- Spring Integration Support - Provides Spring Integration channel adapters and introduces a custom namespace to provide simple, configuration-based use of AMQ from your Spring Integration-based integration architecture.
The project is currently distributed as a Zip, Tar or is available from a Maven repository (or, of course, build from source)
Getting stuck in with AmqTemplate
A quick glance at the project's integration tests will give you a feel for how to use AmqTemplate. To get started, the first things you will have to do is get an AMQ broker running. AmqTemplate is tested against both QPid (0.5) and RabbitMQ 1.7.0 (1.7.1 should also work, but it hasn't been tested at this point in time) so head on over to their sites and get yourself a broker installed according to their instructions.
Once you have an AMQ broker up and running it's time to configure and use your AmqTemplate. To use a local broker you'd do this using regular Spring configuration like the following snippet.
<bean id="rabbitMqTemplateBean"
class="org.opencredo.amq.rabbitmq.RabbitMqTemplate">
<constructor-arg ref="channelFactoryBean" />
</bean>
<bean id="channelFactoryBean"
class="org.opencredo.amq.rabbitmq.DefaultChannelFactory">
<constructor-arg ref="connectionFactoryBean" />
</bean>
<bean id="connectionFactoryBean"
class="org.opencredo.amq.rabbitmq.SingleConnectionConnectionFactory">
<constructor-arg value="localhost" />
</bean>
The amqTemplate bean is then injected into any class that needs to interact with AMQ. In the following code snippet you can see the AmqTemplate being used to asynchronously send a simple string with an encoded timestamp and then receive it back.
String routingKey = "DefaultExchangeTest";
String msg = this.getClass().getSimpleName() + " msg: "
+ (new Timestamp(
System.currentTimeMillis())).toString();
amqTemplate.convertAndSend(routingKey, msg);
Object result = amqTemplate.receiveAndConvert(routingKey);
More samples can be seen in the org.opencredo.amq.amq-template project tests in the projects source.
"Spring" the AMQ integration
With Jonas being a committer on the Spring Integration project and project lead on OpenCredo AMQ, it was kinda inevitable that first-class support for this light-weight approach to implementing integration architecture in your applications would be provided.
All the options require a blog post of their very own to get into in detail, but to give you a taste of how natural this integration is the following sample shows a Spring Integration pipeline that uses our new AMQ namespace support to create a binding between a specified routing key and a particular AMQ queue, which then enables an AMQ outbound channel adapter to send messages from a Spring Integration channel to a specific AMQ exchange.
<!-- AMQ config -->
<beans:bean id="amqTemplate"
class="org.opencredo.amq.rabbitmq.RabbitMqTemplate">
<beans:constructor-arg ref="amqChannelFactory" />
</beans:bean>
<beans:bean id="amqChannelFactory"
class="org.opencredo.amq.rabbitmq.DefaultChannelFactory">
<beans:constructor-arg ref="amqConnectionFactory" />
</beans:bean>
<beans:bean id="amqConnectionFactory"
class="org.opencredo.amq.rabbitmq.SingleConnectionConnectionFactory">
<beans:constructor-arg value="localhost" />
</beans:bean>
<!--
Defines binding between routing-key 'amq-key' and AMQP queue -
'amq-queue'.
-->
<amq:amq-binding id="amqBinding"
routing-key="amq-key">
<amq:queue name="amq-queue" />
</amq:amq-binding>
<!-- Defines AMQP exchange of 'direct' type and its binding. -->
<amq:amq-exchange id="amqExchange" type="direct">
<amq:binding ref="amqBinding" />
</amq:amq-exchange>
<!--
This is SI-AMQ adapter which sends message from SI channel
'messagesChannel' to 'amqExchange' exchange.
-->
<amq:outbound-channel-adapter
default-routing-key="amq-key"
exchange="amqExchange"
template="amqTemplate"
channel="messagesChannel" />
That was just a taster and if you can't wait for the next blog post to see more check out the org.opencredo.amq.amq-samples project in the source.
Summary
OpenCredo AMQ makes it easier to play well with AMQ from both regular Java and Spring Integration environments.
And the development has not stopped there. The next version of the project, as can be seen from the project JIRA, plans to incorporate transaction management with the use of an AMQTransactionManager implementation.
Interested in getting involved?
OpenCredo is committed to open source and as such this project is a typical open source offering where anyone is encouraged to grab the code and get involved by submitting bug reports and patches through the project JIRA.