How To Use OpenLegacy RabbitMQ Consumer
This is just a basic example to configure RabbitMQ consumer/producer API.
If you need it for a specific use case please contact your OpenLegacy Customer Success representative.
Prerequisites:
SDK based on Mainframe CICS ItemDetails Example.
Template RabbitMQ Consumer Project
Configure RabbitMQ queues and exchange via RabbitMQ Management Console, for example by following steps:
Go to Queues Tab → Add new queue.
Name:test.dead-letter.queue
Add another new queue.
Name:test.incoming.queue
Arguments:test.exchange
x-dead-letter-routing-key
=test.dead-letter
Add another new queue.
Name:test.outgoing.queue
Go to Exchange Tab → Add new exchange.
Name:test.exchange
Go to test.exchange.
Bind the input and output queues with the exchange.
Go to Bindings → Add binding from this exchange.
To queue:test.incoming.queue
Routing key:test.in
Add another binding from this exchange.
To queue:test.outgoing.queue
Routing key:test.out
How to Use the OpenLegacy solution for RabbitMQ:
Go to template → project-creation → maven → orchestration-rest-pom.xml.ftl and change version according to your IDE.
Create an API project based on the template mentioned above.
Right click on API project folder → Generate APIs from SDK.
Create a service from the SDK's entities. You need to add an additional input field to each new service - this field is the service-key field. We use "method" as the default value, meaning that you need to add a String field named method.
5. Set OL configuration:
ol:
# OpenLegacy Common Properties (OLCommonProperties) #
common:
cache:
enabled: true
license:
# RabbitMQ Properties (RabbitMqGlobalConsumerProperties) #
rabbitmq:
global-consumer:
consumer:
from-queue: test.incomming.queue # for example
producer:
exchange: test.exchange # for example
routing-key: test.out # for example
service-key: method
6. Set Spring Boot - RabbitMQ configuration (if needed):
# Spring boot RabbitMQ Properties #
spring:
rabbitmq:
host: <YOUR HOST ADDRESS>
port: <port number>
username: <USERNAME>
password: <PASSWORD>
listener:
simple:
# In order to 'dead-letter' messages.
default-requeue-rejected: false
#Number of consumers
concurrency: 3
#Retry configurations
retry:
enabled: true
max-attempts: 4
initial-interval: 10000
7. Done.
How to Publish messages via the RabbitMQ Management Console:
Go to the relevant RabbitMQ exchange → Publish message.
Routing Key:test.in
Payload:{ "method": "item", "itemNum": "1000" }
It is important to add the service-key field. In the example above it is "method". The value of this field needs to be the service that you want to activate. After publishing the message, it will enter the queue and will then be consumed by the OpenLegacy consumer.