Contents

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.

Icon

Name has to be exactly the same as below:

.bindings

Any change in the name will not serve the purpose.

Objects in the .bindings file

ConnectionFactory 

Specify the ConnectionFactory objects in the .bindings file with the  corresponding ClassName and FactoryName for each object.

Example

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:

Icon

destinationName attribute needs to be specified for the destination object.

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
  1. In the Send Configuration panel, click the ellipsis button for the Message Type Configuration property.
  2. Enable the Use XML Interface property and provide a Message type from the drop-down menu. 

    Icon

    By default, it is set to 'Text Message'. If it is an AMQP Message, then 'Map Message' and 'Stream Message' cannot be sent from JMS.


    Figure 1: Message Type Configuration property options for JMSIn:5.0

JMSOut5.0 Configration
  1. In the Receive Configuration page, click the ellipsis button for the Message Type Configuration property.
  2. 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

 

Icon

If the message is not an AMQP message, then configure the same Message Type in both JMSIn and JMSOut components.

Sample .bindings file
# sample Queue for AMQP destination

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

Icon

To know how to add the jars, refer to the Adding Resources To a Microservice section.

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).

  1. In the Provider URL Settings property, specify the JMS Provider as '"RABBIT_MQ".

  2. In the JNDI Settings, Initial Context Factory will be pre-loaded with the value "com.sun.jndi.fscontext.RefFSContextFactory".

    Icon

    The “RefFileSystemContextFactory” element in the Initial Context Factory assumes that JNDI .bindings file is placed at a physical location in the FileSystem.

  3. In the Connection Configuration, specify the location of the JNDI .bindings file in Server URL. 

    Example

    Icon
    Windows
    Unix
  4. To validate the connection, click the Test Button. A confirmation message 'Connection created successfully' gets displayed if the connection is succesful.

    Icon

    In the Destination Configuration, when the property 'AutoCreate Destination' is enabled and if the destination provided is not present in the .bindings file, then it will be created dynamically. If 'AutoCreate Destination' is disabled, then the destination must be declared in the .bindings file.

References

Icon

For JMS Microservices' documentation, follow the links below:

Adaptavist ThemeBuilder EngineAtlassian Confluence