Subscribe and Reading from, and Publish to a TOPIC

Publish to a TOPIC with the EGL add statement; Subscribe and read with get next.

The first time you use an EGL statement with an MQ record during a program, EGL checks to see if there is an active connection to a queue manager. If not, it creates one.

Connecting to queue managers

You can connect to only one queue manager at a time in an EGL program.

EGL automatically connects to the queue manager on the first add or get next statement in a program, using the queue manager name specified in the system resource name associated with the message queue record. If the queue manager name is not specified in case of topic process, then it will not use the default queue manager defined for your system. EGL automatically disconnects from the queue manager when the program ends.

Publishing messages to topics

Publish messages to topics using the add statement with the message topic record as the I/O object. EGL performs the following actions:
  1. Establishes the connection to the queue manager.
  2. Opens the connection to the topic.
  3. Publish the message on the topic.

Subscribing and Reading messages from Topic

Read messages from topic using the get next statement with the message topic record as the I/O object. When you use the get next statement, EGL performs the following actions:

  1. Connects to the queue manager if the queue manager is not already connected.
  2. Opens the queue if the queue is not already open.
  3. Create Subscription durable or non-durable if needed. Otherwise resume with existing subscription.
  4. Gets the next message from the Topic or TopicString. Can use wait interval to read the message.

EGL automatically closes the connection to the queue on program termination.

Committing or rolling back messages

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 is removed.

Limitation on COBOL environment:

  • Topic doesn’t support commit or roll back.