IBM Support

Accessing MQ Provider through EGL Java Application

White Papers


Abstract

Tom Baranski
Senior Software Engineer

EGL applications can communicate with both EGL and non-EGL applications by sending messages via a message broker (an MQ provider). Sending and receiving messages can be deployed on separate target platforms. The target platform can be an application server, a local machine, a CICS Transaction Server, or a Docker container.
This paper details how an EGL Java application can access an MQ provider.

Content

Introduction

Applications can send messages to each other using a message queue or topic managed by a message broker (an MQ provider). 

  • An application can write a message to a queue. 

       When another application consumes the message, then the message takes off the queue.

  • An application can publish a message to a topic and One or more applications can receive the messages by subscribing to that topic.

EGL supports the following MQ providers:

  • IBM® MQ (formerly WebSphere® MQ or MQSeries®)
  • RabbitMQ 
  • Apache ActiveMQ ®

 The EGL runtime handles the underlying communication with the MQ provider. This action allows EGL applications to communicate with EGL and non-EGL applications without knowledge of the communication network's lower levels and the other applications' location.

Prerequisites 

  • IBM Rational Business Developer 9.7 (RBD).
  • IBM MQ, RabbitMQ, or Apache ActiveMQ 
  • Knowledge of developing applications or web services using EGL and RBD.
MQ Providers
EGL supports Message Queues and Topics with the following MQ providers: IBM MQ, RabbitMQ, and Apache ActiveMQ.
For COBOL generation, only IBM MQ is supported. The EGL Runtime handles the underlying communication via AMQP (Advanced Message Queuing Protocol) or JMS (Java Message Service).

IBM® MQ (formerly WebSphere® MQ or MQSeries®).
EGL can communicate with IBM MQ using either AMQP or JMS. 
  • AMQP – this is the default communication between IBM MQ and EGL and supports existing EGL MQ applications, including IBM MQ options records. In this communication, Message Queues are supported but not Topics. 
  • JMS - In this communication, Message Queues and Topics are supported, but not IBM MQ options records

EGL is compatible with the IBM MQ “allclient” jar file (com.ibm.mq.allclient.jar), available with the IBM MQ installation.
For JMS support in standalone EGL Java applications, the JMS API library is required:
  • https://mvnrepository.com/artifact/javax.jms/javax.jms-api/2.0.1
RabbitMQ
EGL can communicate with RabbitMQ using the RabbitMQ Java Client Library 5.x (AMQP). Queues can be accessed directly, or the EGL application can access RabbitMQ Exchanges for publishing and subscribing to topics.
EGL is compatible with Version 5 of the library, available here: RabbitMQ Java Client Library — RabbitMQ
Apache ActiveMQ
EGL can communicate with Apache ActiveMQ via the Apache Qpid JMS Client. Here, Queues and Topics are supported.
EGL Support For MQ
EGL supports MQ using a common framework for I/O. This framework has three components:
  1. An EGL Record type- represents the structure of the data being read/written. 
  2. An EGL logic part (Program/Library/Service)- issues EGL I/O statements against a record variable.
  3. An EGL Resource Association- links the EGL Record to a physical file or system. This resource association is a component of the EGL project’s Build Descriptor.
To create an EGL application that accesses MQ, perform the below steps:
Step 1: Define an EGL record of type MQRecord to describe the structure of the MQ message and whether the message is destined for a queue or a topic (Refer to Figure 1)
Step 2: Declare a Resource Association element of type mq with the same name as the EGL record defined in Step 1. Update the properties required to access the MQ provider. (Refer to Figures 4-6)
Step 3: Create an EGL logic part (Program/Library/Service) and function(s) to perform the MQ access. 
Step 4: Declare a record variable of the type defined in step 1.
Step 5: In the EGL function, code an add or getNext statement against the record variable defined in step 3. (Refer to Figure 2). 
 
MQRecord
EGL provides a built-in Record type called MQRecord, which contains additional properties related to MQ 
queueName / topicName
The name of the resource association element that is to be linked to MQRecord. If the property isTopicRecord value is no (the default), then queueName is used. Otherwise, topicName is used.
isTopicRecord
Specifies whether this MQRecord is for a message queue or topic. The default value of this property is no.
topicString
Identifies the topic that the EGL application will publish/subscribe to. Here, Wildcards and separators can be used.
includeMsgInTransaction
Specifies whether MQ operation is to be transacted. If the value is yes (the default), then MQ operations can be committed or rolled back by the user.
When you combine messages in a transaction that defines a unit of work, the messages can be committed or rolled back as a group. When a unit of work is committed, everything included in the transaction is finalized. When a unit of work is rolled back, everything included in the transaction will be removed.
In other environments, the resources for different managers are committed independently from one another. When user use sysLib.commit() and sysLib.rollback(), EGL automatically issues the appropriate MQ calls for commits and rollbacks.
messageFormat
The format of the message sent and received. The supported formats are mentioned below.
  • BINARY – the MQ record is serialized/deserialized as an unformatted message. This is the default format, and is compatible with EGL applications written prior to RBD 9.7. The sender and receiver application needs to know the structure of the EGL MQ record.
  • TEXT – the MQ record is converted to and from an unformatted string. It has the same effect as BINARY.
  • JSON – the MQ record is converted to and from a JSON-formatted string
subscriptionName
The name of the topic subscription that EGL clients use to listen for topic messages. This name has the following format:

              [ClientID]:subscriptionName

ClientID indicates that this subscription is unique to the EGL client (i.e. non-shared subscription). If this option is omitted, a shared subscription is used.
  • For IBM MQ via JMS, a subscription with the provided name will be created and managed by IBM MQ. Here, predefined subscriptions cannot be used.
  • For RabbitMQ, this option has no effect. Instead, topic exchanges are used, defined in the resource association.
  • For Apache ActiveMQ, the ClientID is mandatory. Shared subscriptions cannot be used.
image 12729
Figure 1 Record definitions for EGL MQ access
MQ Access In EGL
The first time you use an EGL I/O statement with an MQ record during a program, EGL checks if there is an active connection to a queue manager. If not, it creates one. Users can connect to one queue manager at a time in an EGL program.
 
EGL automatically connects to the queue manager on the first Add or getNext statement in a program, using the queue manager name specified in the system resource name associated with the message queue record. In the case of topic process, it will not use the default queue manager defined for your system if the queue manager name is not specified. 
EGL disconnects from the queue manager automatically when the program ends.
 
EGL provides two I/O statements for MQ:
  • Add 
    Writes a message to a message queue or publishes the message to a topic.
  • getNext
    Reads the next message from the message queue or subscribes to a topic.
Committing or rolling back messages

When a user combines message operations in a transaction that defines a unit of work, the message operations can be committed or rolled back as a group. Everything included in the transaction is finalized when a unit of work is committed. When a unit of work is rolled back, everything included in the transaction is reverted to the last commit.
To make commit and rollback accessible, the value of the MQRecord property of includeMsgInTransaction must be set to yes. The EGL function sysLib.commit() and sysLib.rollback() can be used for explicit commits/rollbacks.
  • Commit
    • If the user invokes sysLib.commit(), it issues a close command, or the EGL application/service invocation completes successfully, then the EGL runtime performs a commit.
    • Messages added to the queue or topic will be published.
    • Messages read from a queue will be dequeued.
  • Rollback
    • If the user invokes sysLib.rollback() or an unhandled exception occurs in the EGL application/service invocation, then a EGL runtime performs a rollback to the last commit.
    • Messages added to the queue or topic will not be published.
    • Messages read from a queue will be requeued.
image 12730
Figure 2 EGL Logic For MQ Access
Specifying the message destination at run time

EGL MQRecords have an additional property resourceAssociation that allows the user to change the message queue or topic at run time – this sets the runtime value of the systemName property defined in the Resource Association. In Figure 3, the topic associated with the mynews MQ record has been changed from CONTINENTS/AUSTRALIA (Refer to record definition in Figure 1) to CONTINENTS/EUROPE.
image 12732
Figure 3 Specifying the message destination at run time
EGL MQ Resource Associations
For the EGL runtime to access message queues and topics, a Resource Association must be created to link the MQRecord to an MQ provider. The name of the Resource Association must match the queueName or topicName of the MQRecord.
IBM MQ

Sample properties for IBM MQ are shown in Figure 4, which links the MQRecord with topicName CONTT (Figure 1) to an IBM MQ system. 
Note that exchangeName and exchangeType are not applicable for IBM MQ.
image 12733
Figure 4 Resource Association for IBM MQ
  • Provider
    • IBMMQ – Supports existing EGL MQ applications that use IBM MQ options records. Here, Message Queues are supported but not Topics. It uses the IBM AMQP Java driver.
    • IBMMQJMS - This Supports Message Queues and Topics but does not support IBM MQ options records. It uses IBM MQ JMS driver.
  • Channel
    • This is the name of the IBM MQ channel used to connect to.
  • systemName
    • Specifies the IBM MQ queue manager and the initial values of the queue name or topic string, in one the following format:
      • QueueManagerName:Quename
      • QueueManagerName::TopicString
      • QueueManagerName
  • subscriptionName
    • The initial value of the subscriptionName in the MQ record property.
RabbitMQ

Sample properties for RabbitMQ are shown in Figure 5 which links the MQRecord with a topicName of CONTTRAB to a RabbitMQ system.

Note: channel and subscriptionName are not applicable for RabbitMQ.
image 12734
Figure 5 Resource Association for RabbitMQ
  • Provider
    RABBITMQ - Supports Message Queues and Topics. It uses RabbitMQ Java Client Library.
  • exchangeName
    This is the name of the RabbitMQ message exchange used to connect to. If the exchange does not exist, an exchange will be created using the exchangeType property defined in the resource association.
  • exchangeType
    • When creating a RabbitMQ exchange, this property specifies the type of the message exchange. The topicString property becomes a routing key for routing messages in the exchange. Refer to the supported types mentioned below:
      • NONE – no message exchange is used. Queues are accessed directly. Use this, if the value of isTopicRecord is set to no.
      • DIRECT is for 1-Many exchange listeners with the same single-word routing key. This option is available if the value of isTopicRecord is set to yes.
      • FANOUT is for 1-Many exchange listeners, regardless of routing key. This option is available if the value of isTopicRecord is set to yes.
      • TOPIC is for 1-Many exchange listeners with the same routing key. This key contains separators and wildcards. This option is available if the value of isTopicRecord is set to yes.
    • If the value of the MQ record option isTopicRecord is set to yes, then the default value of exchangeType is TOPIC. Otherwise, the default value is NONE.
  • systemName
  • Specifies the RabbitMQ virtual host name and the initial values of the queue name or topic string, in one the following format:
    • VirtualHostName:Quename
    • VirtualHostName::TopicString
    • VirtualHostName
Apache ActiveMQ
Sample properties for ActiveMQ are shown in Figure6, which links the MQRecord with a topicName of CONTTAC to an ActiveMQ system. 
Note: channel, exchangeName, and exchangeType are not applicable for ActiveMQ.
image 12735
Figure 6 Resource Association for Apache ActiveMQ
  • Provider
    • ACTIVEMQJMS – It uses the Apache Qpid JMS Driver to access ActiveMQ
  • systemName
    • Specifies the initial values of the queue name or topic string, in one the following format:
    •  :Quename
    • ::TopicString
    •      
  • subscriptionName
    • The initial value of the subscriptionName MQ record property.
Common Properties
These are the properties, which have the same meaning across all MQ providers.
  • conversionTable
    • When the messageFormat is NONE or TEXT, this option specifies the name of the conversion table used to perform automatic data conversion during the message access. 
  • Host
    • The TCP/IP hostname of the MQ provider
  • Port
    • The TCP/IP port number of the MQ provider
  • User
    • The username to connect with
  • Password
    • The password for the user
Deploying EGL MQ Applications
EGL MQ applications can be deployed as standalone applications or web services. 
For standalone Java-generated applications, the drivers need to access the MQ provider. The user must provide the information in the Java classpath (Refer to Figure 7)
 
image 12736
Figure 7 Java Build Path for IBM MQ access
For web applications, the drivers need to access the MQ provider. The user must provide the information in the WEB-INF/lib folder (Refer to Figure 8).
image 12737
Figure 8 Web Library Path for IBM MQ access
Conclusion
This whitepaper details how an EGL application can send or receive messages using message queues or publishing/subscribing to topics.

[{"Type":"MASTER","Line of Business":{"code":"LOB35","label":"Mainframe SW"},"Business Unit":{"code":"BU058","label":"IBM Infrastructure w\/TPS"},"Product":{"code":"SSMQ79","label":"Rational Business Developer"},"ARM Category":[{"code":"a8m0z0000000BB1AAM","label":"Rational Business Developer"}],"ARM Case Number":"","Platform":[{"code":"PF016","label":"Linux"},{"code":"PF033","label":"Windows"}],"Version":"9.7.0"}]

Document Information

Modified date:
16 August 2022

UID

ibm16608934