KB Article #186820
JMS with RabbitMQ
Problem
- How to make API Gateway connecting to RabbitMQ using JMS?
- This configuration has been tested with the following version of the product
API Gateway 7.7.20240228 (Feb 24)
RabbitMQ 3
- For additional information related to JMS configuration in API Gateway, please refer to the documentation:
https://docs.axway.com/bundle/axway-open-docs/page...
Resolution
- The following jars need to be added in the ext/lib/ folder of your API Gateway installation:
amqp-client (tested with version 5.21.0)
fscontext (tested with version 4.6-b01)
javax.jms-api (tested with version 2.0.1)
rabbitmq-jms (tested with version 2.9.0)
A restart of API Gateway is needed once the jars have been copied.
- Create a .bindings file in an empty folder, as example, in a rabbitmq/ folder under your API Gateway installation folder. The content of the file should look like the following (it's a sample that should be adapted for your needs):
# Define the Connection Factory object ConnectionFactory/ClassName=javax.jms.ConnectionFactory ConnectionFactory/FactoryName=com.rabbitmq.jms.admin.RMQObjectFactory ConnectionFactory/RefAddr/0/Content=jms/ConnectionFactory ConnectionFactory/RefAddr/0/Type=name ConnectionFactory/RefAddr/0/Encoding=String ConnectionFactory/RefAddr/1/Content=javax.jms.ConnectionFactory ConnectionFactory/RefAddr/1/Type=type ConnectionFactory/RefAddr/1/Encoding=String ConnectionFactory/RefAddr/2/Content=com.rabbitmq.jms.admin.RMQObjectFactory ConnectionFactory/RefAddr/2/Type=factory ConnectionFactory/RefAddr/2/Encoding=String # Change this line accordingly if the broker is not at localhost ConnectionFactory/RefAddr/3/Content=localhost ConnectionFactory/RefAddr/3/Type=host ConnectionFactory/RefAddr/3/Encoding=String # Define a queue queue1/ClassName=com.rabbitmq.jms.admin.RMQDestination queue1/FactoryName=com.rabbitmq.jms.admin.RMQObjectFactory queue1/RefAddr/0/Content=jms/Queue queue1/RefAddr/0/Type=name queue1/RefAddr/0/Encoding=String queue1/RefAddr/1/Content=javax.jms.Queue queue1/RefAddr/1/Type=type queue1/RefAddr/1/Encoding=String queue1/RefAddr/2/Content=com.rabbitmq.jms.admin.RMQObjectFactory queue1/RefAddr/2/Type=factory queue1/RefAddr/2/Encoding=String queue1/RefAddr/3/Content=queue1 queue1/RefAddr/3/Type=destinationName queue1/RefAddr/3/Encoding=String # Define another queue queue2/ClassName=com.rabbitmq.jms.admin.RMQDestination queue2/FactoryName=com.rabbitmq.jms.admin.RMQObjectFactory queue2/RefAddr/0/Content=jms/Queue queue2/RefAddr/0/Type=name queue2/RefAddr/0/Encoding=String queue2/RefAddr/1/Content=javax.jms.Queue queue2/RefAddr/1/Type=type queue2/RefAddr/1/Encoding=String queue2/RefAddr/2/Content=com.rabbitmq.jms.admin.RMQObjectFactory queue2/RefAddr/2/Type=factory queue2/RefAddr/2/Encoding=String queue2/RefAddr/3/Content=queue2 queue2/RefAddr/3/Type=destinationName queue2/RefAddr/3/Encoding=String
A restart of the instance, or a new deployment, is needed to apply the changes made in this file.
- In the instance configuration, define a JMS Listener with the following information:
Provider URL: file:/opt/axway/apigateway/rabbitmq/
(to adapt with the folder containing the .bindings file created previously)
Initial Context Factory: com.sun.jndi.fscontext.RefFSContextFactory
Connection Factory: ConnectionFactory
(set username and password if needed to connect to RabbitMQ).
- To send message to a queue, create a policy including a Send to JMS filter, as example, to send on queue1:
- To read message from a queue, create a policy with a Read from JMS filter, or create a JMS Consumer, as example, to read message from queue2: