- Creating the .bindings file
- Adding Dependencies
- Configuring the Microservice
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
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.
A 'name' attribute contains the value 'jms/ConnectionFactory' of type 'String'.
A 'type' attribute contains the value 'javax.jms.ConnectionFactory' which is of the type 'String'.
A 'factory' attribute contains the value 'com.rabbitmq.jms.admin.RMQObjectFactory' which is of the type 'String'.
hostname attribute can be created for ConnectionFactory object as below.
Similar to that of ConnectionFactory objects, destinations can be specified as objects in .bindings file.
Considering the destination as queue, to define the destination object, specify the name, type, factory and destinationName attributes.
Take for example queue name as 'queue1', then the object definition looks like:
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:
If the message is amqp message, then the configuration of JMSIn:5.0 and JMSOut:5.0 microservices are shown below,
- 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
- 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
To use JMS API of RabbitMQ, add the following jars to the JMSAdapters node under System Lib in the Micro Service Repository panel:
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.