Integrating MagooClient with RabbitMQ (1)

Setup

The RabbitMQ transport is based on the RabbitMQ Java client library which allows Java code to interface directly with Rabbit AMQP exchanges as opposed to going through a JMS layer. In order to configure a RabbitMQ transport, it is necessary to download and install the RabbitMQ client JAR files as these are not shipped with the Magoo installation. The binary package with all of the required JARs can be obtained as a ZIP e.g. rabbitmq-java-client-bin-1.7.2.zip from http://www.rabbitmq.com/java-client.html

 

Exchange Types

The RabbitMQ transport supports interaction with all three exchange types (direct, topic and fanout) and allows an exchange, along with its type, to be automatically declared on connection. As the semantics for message delivery differ across the exchange types, separate sections are provided below to illustrate message handling. In all cases, the publicly available broker at dev.rabbitmq.com could also be used to try out the demo scenarios.

 

The RabbitMQ transport allows exchanges and queues to be automatically declared when setting up a listener on a particular exchange/routing key. Note that there is no auto-declare capability on sending.

 

A Note on Message Properties

The RabbitMQ Transport maps the AMQP properties to user visible message properties as follows:

  • CorrelationId -> Subject
  • Priority -> Priority
  • UserId -> Sender
  • Timestamp -> Sent
In addition, if a replyTo is set on a received message then this will be used as the destination on creation of a reply message.

 

Configuring a Connection to a Direct Exchange

The RabbitMQ transport allows exchanges and queues to be automatically declared when setting up a listener on a particular exchange/routing key. Note that there is no auto-declare capability on sending.

The configuration dialog for a RabbitMQ transport with an auto-declared, durable exchange and queue bound to the routing key test is shown below:

 

 

 

Sending a Message

Once the transport has been configured, a plain-text test message can be sent to validate correct operation. To create a message, select the New Text Message from the Message menu in the main MagooClient window. Sample message text may be entered as can a subject which will be mapped to the message correlationId property.


To publish a message to a RabbitMQ exchange using a routing key use the destination format rabbitmq:[<exchange_name>/]<routing_key>. Therefore on the To: line enter the destination rabbitmq:magooqueues/test and click on Send. The message will be published to the magooqueues exchange with the routing key test. As the magooqueues/test transport has established a queue testqueue bound to routing key test, the message will be delivered to testqueue the transport will pick it up from the queue and it should immediately appear in the inbox:

 

 

Note that when sending to a direct exchange, the RabbitMQ transport publishes with the mandatory flag set to true but immediate flag set to false to allow for typical store and forward behaviour. This means that if no durable queues have been bound to the routing key then an error condition will occur and the message will remain in the outbox. For example, if an attempt is made to send to a non-existent queue e.g. destination rabbitmq:magooqueues/notthere then the message should be visible in the outbox as follows:




The RabbitMQ magooqueues/test transport will flag an error condition and will continue to re-publish the message every 60 seconds pending availability of a queue bound to the required routing key (notthere). This can be checked via the transport log:


1 2 Next >