Distributed Pub/Sub allows applications connected to separate queue managers communicate via publish and subscribe. This article explains the separate ways queue managers can be connected to allow publish and subscribe from any queue managers. Following are two topologies how queue managers can be connected
â€¢ Hierarchical topology
â€¢ Clusters topology
Hierarchical topology: – In hierarchical topology, queue managers are grouped together in a hierarchy connected via point to point channels or cluster channels. A parent and child relationship is defined to build the hierarchy.
Let us see how to connect queue manager in hierarchy topology. Setup includes two child queue manager QM2 and QM3 connected with parent queue manager QM1
- Create queue manager QM1, QM2 and QM3 and start the queue managers.
Enable queued publish/subscribe mode. To do this on each queue manager, using runmqsc command ALTER QMGR specify PSMODE to ENABLED
- Establish point-to-point channel connections between queue manager using transmission queue with same name as parent queue manager.
On QM2 define transmission queue to QM1. Define sender channel to QM1 and receiver channel, define the listener and start the listener.
- On QM3 define transmission queue to QM1. Define sender channel to QM1 and receiver channel for sender channel created on QM1 for QM3.
- On QM1 define transmission queues to QM2 and QM3. Define sender channel to QM2 and QM3 and receiver channel for sender channel created on QM2 and QM3 for QM1.
- Start the channels on queue managers. Ensure all channel goes running by checking dis chs runmqsc command
- On QM2 define transmission queue to QM1. Define sender channel to QM1 and receiver channel, define the listener and start the listener.
Connect queue manager to a parent queue manager. On all child queue manager, using runmqsc command ALTER QMGR specify PARENT to parent queue manager name. In this example QM2 and QM3 are child of QM1, On QM2 and QM3 alter queue manager to set PARENT as QM1
Ensure child queue manager are connected to parent queue manager using display pubsub all runmqsc command on all the queue managers.
Define Topic object and test the setup by publishing message from one queue manager to the other.On QM2,defined the following topic
Verify SetUp:- Perform the following steps to verify the setup
- Using amqspub and amqssub application publish and subscribe the topic.
- On one windows /opt/mqm/samp/bin/amqspub /Sport/Soccer QM2
- On other windows /opt/mqm/samp/bin/amqssub /Sport/Soccer QM1
- On other windows /opt/mqm/samp/bin/amqssub /Sport/Soccer QM3
- Ensure application amqssub on QM1 and QM3 gets messages published using amqspub on QM2.
To Disconnect a queue manager from a hierarchy topology:- Use runmqsc command ALTER QMGR PARENT(”) command to disconnect a queue manager from a broker hierarchy. You can disconnect a queue manager in any order at any time. The corresponding request to update the parent is sent when the connection between the queue managers is running. You can delete any streams, queues and manually defined channels that are no longer needed.
Publish Subscribe Cluster: – A publish/subscribe cluster is a standard WebSphere MQ cluster with one or more cluster topics objects. Cluster topics are administrative topics with the cluster attribute defined. When you define a cluster topic, the cluster topic is published to the full repositories. The full repositories then push the cluster topic definition to all queue managers within the cluster, making the same cluster topic available to publishers and subscribers at any queue manager in the cluster.
Let us see how to connect queue manager in cluster topology. Setup includes 3 queue managers QM1, QM2 as full repository and QM3 as partial repository
Define full repository for QM1 and QM2
Defining cluster sender and receiver channels for QM1, define listeners and start the listener:-
- Similarly for QM2, Defining cluster sender and receiver channels, define listener and start the listener
- Similarly for QM3, Defining cluster sender and receiver channels , define listener and start listener
- Define cluster topic and define scope of topic. On QM1 define cluster topic scores and set the publish scope of topic scores to ALL
Verify the setup:- To verify the setup use the following commands to ensure cluster queue manager and topic are visible on all cluster queue managers. Ensure channel status is running using the below commands
To test the setup :- To test the setup
- In one window – /opt/mqm/samp/bin/amqssub /FOOTBALL/scores QM2
- In another window – /opt/mqm/samp/bin/amqspub /FOOTBALL/scores QM3
Removing cluster topic from cluster:- In the example we are removing TOPIC SCORES from QM1
- Remove the topic from cluster
- Disable the TOPIC and Monitor the topic until it is empty
- Check if channel does not have indoubt messages
Scope of Pub Sub in distributed environment:- You can control the flow of publications and subscriptions within the topology by choosing whether each publication and subscription is either local or global. Local publications and subscriptions are not propagated beyond the queue manager to which the publisher or subscriber is connected.
Publication scope :- The scope of a publication controls whether queue managers forward a publication to remote queue managers. The PUBSCOPE topic attribute is used to determine the scope of publications made to a specific topic. You can set the attribute to one of the following values:
- QMGR – The publication is delivered only to local subscribers.
- ALL – The publication is delivered to local subscribers and subscribers connected to remote queue managers. These publications are called global publications.
- ASPARENT – Use the PUBSCOPE setting of the parent.
Subscription scope :- Similarly, the scope of subscriptions can be controlled administratively using the SUBSCOPE attribute on a topic object. You can set the attribute to one of the following values:
- QMGR – The subscription is not propagated to directly connected queue managers, and only receives publications from local publishers.
- ALL – The subscription is propagated directly to connected queue managers and receives publications from local publishers and remote publishers via directly connected queue managers.
- ASPARENT – Use the SUBSCOPE setting of the parent.