Creating the .bindings file
To connect Rabbit MQ using JMS API, 'RefFSContextFactory' has to be used as Initial Context Factory to lookup JNDI objects. In order to lookup, we need to create a '.bindings' file with JNDI administered objects.
To create the bindings file, save a text (.txt) file naming it as ".bindings" and edit the file by providing object definitions represented in Content/Type/Encoding triplet as per requirement.
Objects in the .bindings file
ConnectionFactory
Specify the ConnectionFactory objects in the .bindings file with the corresponding ClassName and FactoryName for each object.
This .bindings file contains attributes that are used to lookup a ConnectionFactory object and other JNDI resources. Each attribute has a name, a value and the type of variable that holds the value.
Attributes in the ConnectionFactory object
The attributes to lookup connection factory object are name, type, factory, and hostname.
name
A 'name' attribute contains the value 'jms/ConnectionFactory' of type 'String'.
type
A 'type' attribute contains the value 'javax.jms.ConnectionFactory' which is of the type 'String'.
factory
A 'factory' attribute contains the value 'com.rabbitmq.jms.admin.RMQObjectFactory' which is of the type 'String'.
hostname
hostname attribute can be created for ConnectionFactory object as below.
Destinations
Similar to that of ConnectionFactory objects, destinations can be specified as objects in .bindings file.
Examples
Considering the destination as queue, to define the destination object, specify the name, type, factory and destinationName attributes.
Queue
Take for example queue name as 'queue1', then the object definition looks like:
Topic
If the destination is Topic, an example of definition of Topic is given below:
Sending AMQP message to the destination
If AMQP message needs to be sent to the destination, then provide additional attributes such as:
- amqp
- amqpExchangeName
- amqpRoutingKey
- amqpQueueName.
If the message is amqp message, then the configuration of JMSIn:5.0 and JMSOut:5.0 microservices are shown below,
JMSIn:5.0 Configuration
- In the Send Configuration panel, click the ellipsis button for the Message Type Configuration property.
Enable the Use XML Interface property and provide a Message type from the drop-down menu.
Figure 1: Message Type Configuration property options for JMSIn:5.0
JMSOut5.0 Configration
- In the Receive Configuration page, click the ellipsis button for the Message Type Configuration property.
- If the input does not contain any XML content, then enable the Byte Message as Text property. Else, enable the Use XML Interface property and choose 'BYTE_MESSAGE_AS_TEXT' in the Message Type drop down.
Figure 2: Message Type Configuration property options for JMSOut:5.0
Adding Dependencies
To use JMS API of RabbitMQ, add the following jars to the JMSAdapters node under System Lib in the Micro Service Repository panel:
amqp-client-4.1.1.jar
fscontext-4.5-b25.jar
rabbitmq-jms-client.jar
Configuring the Microservice
The JMS microservice connection related properties are configured in the landing panel of the microservice CPS (Managed Connection Factory panel for version 4 and JMS Connection Configuration for version 5).
- In the Provider URL Settings property, specify the JMS Provider as '"RABBIT_MQ".
In the JNDI Settings, Initial Context Factory will be pre-loaded with the value "com.sun.jndi.fscontext.RefFSContextFactory".
In the Connection Configuration, specify the location of the JNDI .bindings file in Server URL.
To validate the connection, click the Test Button. A confirmation message 'Connection created successfully' gets displayed if the connection is succesful.