Date Created: Sat 23-Feb-2008

Related Document Categories:

Get my WebSphere MQ course here >> http://www.themiddlewareshop.com/products/


MQ tutorial on how to create an MQ hub and spoke architecture.

In this article I am going to create a Hub and Spoke MQ architecture on Linux. The result of this example will explain why using an MQ cluster has less administrative overhead.

First we will create the hub of our hub and spoke topology. We will call it hub.Then we will create spoke queue managers and configure intercommunication between hub and spokes. We will by example show how spokes can use the hub service.

------------------------------
Creating the hub
------------------------------

crtmqm wmqnode01/hub
WebSphere MQ queue manager created.
Creating or replacing default objects for wmqnode01/hub.
Default objects statistics : 40 created. 0 replaced. 0 failed.
Completing setup.
Setup completed.

What we will now do is create a dead letter queue to ensure we do not loose non-persistent messages if a destination is incorrect. Note the reason we use MQ explorer a lot in these examples is that without a GUI it is very doifficult to see what is happening to messages in a hub and spoke environment due to the number of channels.

strmqm wmqnode01/hub
WebSphere MQ queue manager 'wmqnode01/hub' starting.
5 log records accessed on queue manager 'wmqnode01/hub' during the log replay phase.
Log replay for queue manager 'wmqnode01/hub' complete.
Transaction manager state recovered for queue manager 'wmqnode01/hub'.
WebSphere MQ queue manager 'wmqnode01/hub' started.

runmqsc wmqnode01/hub

define qlocal('dead.letters')

alter qmgr deadq('dead.letters')

runmqsc wmqnode01/hub
5724-H72 (C) Copyright IBM Corp. 1994, 2005. ALL RIGHTS RESERVED.
Starting MQSC for queue manager wmqnode01/hub.


define qlocal('dead.letters')
1 : define qlocal('dead.letters')
AMQ8006: WebSphere MQ queue created.
alter qmgr deadq('dead.letters')
2 : alter qmgr deadq('dead.letters')
AMQ8005: WebSphere MQ queue manager changed.
end
3 : end
2 MQSC commands read.
No commands have a syntax error.
All valid MQSC commands were processed.

-----------------------------
Create a receiver channel on the hub queue manager
-----------------------------
We now need to create a receiver channel object on the hub queue manager. Remember that channels require at least one receiver or one sender object at each end.

runmqsc wmqnode01/hub
5724-H72 (C) Copyright IBM Corp. 1994, 2005. ALL RIGHTS RESERVED.
Starting MQSC for queue manager wmqnode01/hub.


define channel('to.wmqnode01/hub') chltype(rcvr)
1 : define channel('to.wmqnode01/hub') chltype(rcvr)
AMQ8014: WebSphere MQ channel created.
dis channel('to.wmqnode01/hub')
2 : dis channel('to.wmqnode01/hub')
AMQ8414: Display Channel details.
CHANNEL(r.wmqnode01/hub) CHLTYPE(RCVR)
ALTDATE(2008-02-23) ALTTIME(14.33.27)
BATCHSZ(50) COMPHDR(NONE)
COMPMSG(NONE) DESCR( )
HBINT(300) KAINT(AUTO)
MAXMSGL(4194304) MCAUSER( )
MONCHL(QMGR) MRDATA( )
MREXIT( ) MRRTY(10)
MRTMR(1000) MSGDATA( )
MSGEXIT( ) NPMSPEED(FAST)
PUTAUT(DEF) RCVDATA( )
RCVEXIT( ) SCYDATA( )
SCYEXIT( ) SENDDATA( )
SENDEXIT( ) SEQWRAP(999999999)
SSLCAUTH(REQUIRED) SSLCIPH( )
SSLPEER( ) STATCHL(QMGR)
TRPTYPE(TCP)
end
3 : end
2 MQSC commands read.
No commands have a syntax error.
All valid MQSC commands were processed.

What we are going to for now is create a spoke queue manager and appropriate listeners.

The first spoke will be called wmqnode01/spoke as it resides on the hostname wmqnode01. Each queue manager must have a listener defined. Because a number of queue managers can be hosted on the same machine, it is recommended that the port number is relevant to the queue manager name to avoid confusion. The first spoke queue manager created will have a listener running on port 60011. We will increase the port number by one for each queue manager. E.g spoke 1 will have the hostname wmqnode01/spoke and port 60011 and spoke 2 will have the host name wmqnode01/spoke and port 60012.

Note: Different queue managers on different machines can have a listener running on the same port number. However, two queue managers on the same machine cannot.

crtmqm wmqnode01/spoke
WebSphere MQ queue manager created.
Creating or replacing default objects for wmqnode01/spoke.
Default objects statistics : 40 created. 0 replaced. 0 failed.
Completing setup.
Setup completed.

-----------------------------------
Creating the channels and thus defining the transmission queue and ip/port settings.
----------------------------------

Note: A transmission queue is a local queue object that has been specified to be used as a transmission queue.

strmqm wmqnode01/spoke
WebSphere MQ queue manager 'wmqnode01/spoke' starting.
5 log records accessed on queue manager 'wmqnode01/spoke' during the log replay phase.
Log replay for queue manager 'wmqnode01/spoke' complete.
Transaction manager state recovered for queue manager 'wmqnode01/spoke'.
WebSphere MQ queue manager 'wmqnode01/spoke' started.

---------------------------
Create a transmission queue on the sending queue manager
---------------------------

runmqsc wmqnode01/spoke
5724-H72 (C) Copyright IBM Corp. 1994, 2005. ALL RIGHTS RESERVED.
Starting MQSC for queue manager wmqnode01/spoke.


define qlocal('wmqnode01/hub') usage (xmitq) +
descr('Transmission queue for messages to wmqnode01/hub') 1 : define qlocal('wmqnode01/hub') usage (xmitq) +

: descr('Transmission queue for messages to wmqnode01/hub')
AMQ8006: WebSphere MQ queue created.
end
2 : end
One MQSC command read.
No commands have a syntax error.
All valid MQSC commands were processed.

------------------------------
Create sending channel object on spoke queue manager
------------------------------

A sender channel object allows a channel to be established from a queue manager to another queue manager in the infrastructure. The name of the sender channel object must match the name of a remote channel object on the destination queue manager of a compatible type.

We have already defined a receiver channel object on the hub queue manager (see above), which will be used by all connecting spoke queue managers.

A channel takes messages from a single transmission queue on one queue manager and transfers them to the remote queue manager.

runmqsc wmqnode01/spoke
5724-H72 (C) Copyright IBM Corp. 1994, 2005. ALL RIGHTS RESERVED.
Starting MQSC for queue manager wmqnode01/spoke.


define channel('to.wmqnode01/hub') chltype(sdr) +
conname('wmqnode01(60000)') xmitq('wmqnode01/hub') 1 : define channel('to.wmqnode01/hub') chltype(sdr) +

: conname('wmqnode01(60000)') xmitq('wmqnode01/hub')
AMQ8014: WebSphere MQ channel created.
end
2 : end
One MQSC command read.
No commands have a syntax error.
All valid MQSC commands were processed.

Test the channel using a WebSphere MQ ping

runmqsc wmqnode01/spoke
5724-H72 (C) Copyright IBM Corp. 1994, 2005. ALL RIGHTS RESERVED.
Starting MQSC for queue manager wmqnode01/spoke.


ping channel('to.wmqnode01/hub')
1 : ping channel('to.wmqnode01/hub')
AMQ9202: Remote host 'websphere (192.168.0.60) (60000)' not available, retry later.
end
2 : end
One MQSC command read.
No commands have a syntax error.
One valid MQSC command could not be processed.

The reason is that we need to create the listeners for the hub and spoke queue managers.

You can refer to the article on how to create listeners here

-------------------
Hub Listener
-------------------

runmqsc wmqnode01/hub
5724-H72 (C) Copyright IBM Corp. 1994, 2005. ALL RIGHTS RESERVED.
Starting MQSC for queue manager wmqnode01/hub.


define listener(hub.listener) trptype(TCP) port(60000) ipaddr(192.168.0.60)
1 : define listener(hub.listener) trptype(TCP) port(60000) ipaddr(192.168.0.60)
AMQ8626: WebSphere MQ listener created.
start listener(hub.listener)
2 : start listener(hub.listener)
AMQ8021: Request to start WebSphere MQ Listener accepted.
end
3 : end
2 MQSC commands read.
No commands have a syntax error.
All valid MQSC commands were processed.

-------------------
spoke 1 Listener
-------------------


runmqsc wmqnode01/spoke
5724-H72 (C) Copyright IBM Corp. 1994, 2005. ALL RIGHTS RESERVED.
Starting MQSC for queue manager wmqnode01/spoke.


define listener(spoke1.listener) trptype(TCP) port(60011) ipaddr(192.168.0.60)
1 : define listener(spoke1.listener) trptype(TCP) port(60011) ipaddr(192.168.0.60)
AMQ8626: WebSphere MQ listener created.
start listener(spoke1.listener)
2 : start listener(spoke1.listener)
AMQ8021: Request to start WebSphere MQ Listener accepted.
end
3 : end
2 MQSC commands read.
No commands have a syntax error.
One valid MQSC command could not be processed.

We must also add the SYSTEM.ADMIN.SVRCONN channel so we can connect to the queue managers.

runmqsc wmqnode01/spoke
5724-H72 (C) Copyright IBM Corp. 1994, 2005. ALL RIGHTS RESERVED.
Starting MQSC for queue manager wmqnode01/spoke.


define channel(SYSTEM.ADMIN.SVRCONN) chltype(svrconn)
1 : define channel(SYSTEM.ADMIN.SVRCONN) chltype(svrconn)
AMQ8014: WebSphere MQ channel created.
end
2 : end
One MQSC command read.
No commands have a syntax error.
All valid MQSC commands were processed.

runmqsc wmqnode01/hub
5724-H72 (C) Copyright IBM Corp. 1994, 2005. ALL RIGHTS RESERVED.
Starting MQSC for queue manager wmqnode01/hub.

-------------------------

define channel(SYSTEM.ADMIN.SVRCONN) chltype(svrconn)
1 : define channel(SYSTEM.ADMIN.SVRCONN) chltype(svrconn)
AMQ8014: WebSphere MQ channel created.
end
2 : end
One MQSC command read.
No commands have a syntax error.
All valid MQSC commands were processed.


Launch MQ Explorer














You can now see the two queue managers, one hub and one spoke, which both exists on the physical machine 192.168.0.60.



What can do now is a brief look at that channels and listeners we have













What we are going to do now is start the channel to.wmqnode1/hub














We have successfully create a channel connection between a spoke queue manager and a hub queue manager. We can now use the ping command to prove the channel is running using MQSC.

runmqsc wmqnode01/spoke
5724-H72 (C) Copyright IBM Corp. 1994, 2005. ALL RIGHTS RESERVED.
Starting MQSC for queue manager wmqnode01/spoke.


ping channel('to.wmqnode01/hub')
1 : ping channel('to.wmqnode01/hub')
AMQ9514: Channel 'to.wmqnode01/hub' is in use.
end
2 : end
One MQSC command read.
No commands have a syntax error.
One valid MQSC command could not be processed.

A useful feature of channels is that we can set them to automatically start if a message arrives on a transmission queue. What this means is that the channel can remain in an unused state until there is actually work to do. We use a trigger to do this. Remember the transmission queue is configured on the sending queue manager. The work transmission is key.

runmqsc wmqnode01/spoke
5724-H72 (C) Copyright IBM Corp. 1994, 2005. ALL RIGHTS RESERVED.
Starting MQSC for queue manager wmqnode01/spoke.


alter qlocal('wmqnode01/hub') trigger trigtype(first) +
trigdata('to.wmqnode01/hub') initq('system.channel.initq') 1 : alter qlocal('wmqnode01/hub') trigger trigtype(first) +

: trigdata('to.wmqnode01/hub') initq('system.channel.initq')
AMQ8008: WebSphere MQ queue changed.
end
2 : end
One MQSC command read.
No commands have a syntax error.
All valid MQSC commands were processed.

-------------------------------
Sending a test message
-------------------------------

We are going to send a test message through the channel to the hub queue manager.We specify that the destination of the message is on wmqnode01/hub so that the wueue manager does not need any local knowledge of the queue. The spoke queue manager knows about the wmqnode01/hub queue manager, because it has a transmission queue of the correct name. It is by this mechanism that replies are sent through a WebSphere MQ infrastructure to a specific queue on a specific queue manager.

amqsput queue1 wmqnode01/spoke 8208 0 wmqnode01/hub

The following parameters are passed to this sample:
– queue1 is the name of the queue on'wmqnode01/hub.
– host2/spoke is the name of the queue manager being connected to.
– 8208 is a decimal value requesting options to be passed to the MQOPEN call. This is not important to the example. It is requesting that the queue is opened for output to put messages and to fail any subsequent puts if the queue manager is quiescing.
– 0 requests that no options are passed to the MQCLOSE call. This is not
important to the example.

The message is delivered onto the transmission queue by the spoke queue manager. This causes a trigger message to be passed to the queue manager’s channel initiator through the SYSTEM.CHANNEL.INITQ. The channel starts, and the messages flow across to the remote queue manager. The remote message channel agent (MCA), created based on the receiver channel object onwmqnode01/hub, puts this message to the specified queue on that queue manager.

/opt/mqm/samp/bin/amqsput queue1 wmqnode01/spoke 8208 0 wmqnode01/hub
Sample AMQSPUT0 start
target queue is queue1
target queue manager is wmqnode01/hub
/opt/mqm/samp/bin/amqsput queue1 wAMQ.*
open options are 8208
MQOPEN ended with reason code 2086
unable to open queue for output
Sample AMQSPUT0 end
Sample AMQSPUT0 start
target queue is queue1
target queue manager is wmqnode01/hub
open options are 8208
Test
<enter>
close options are 0
Sample AMQSPUT0 end


We have now placed a message on the channel from spoke 1. since there is no destination queue called queue1 the message will appear in the dead.letters queue on the hub queue manager as there is not valid destination.

What we need to do now is have a look at MQ explorer so we can learn how to track the message.



We are going to browse the messages in the dead.letters queue





We then go into the message itself to look at the destination:



We can see that the destination queue is queue1 and since we do not have a queue1 the message is pout in the dead.letters queue.














/opt/mqm/samp/bin/amqsput queue1 wmqnode01/spoke 8208 0 wmqnode01/hub
Sample AMQSPUT0 start
target queue is queue1
target queue manager is wmqnode01/hub
open options are 8208
test2

close options are 0
Sample AMQSPUT0 end




The new message arrives as the queue1 queue exists. We still have a message on the dead.letter queue, how do we move it to queue1?

If both the queues are local queue then the only way to move is to have an external application getting messages from one queue and putting it to another queue. Queue Managers can not do it for you in any case after the event. However there are tools to help you do this.

You download the MA01 SupportPac from IBM, and use the Q utility to move the messages from one queue to another, let's try this and see if it works.

http://www-1.ibm.com/support/docview.wss?rs=171&uid=swg24000647&loc=en_US&cs=utf-8&lang=en

Unzip ma01.zip and scp the q binary to an appropriate folder on the linux server.



Before using q



Move messages between Queues:

q -mwmqnode01/hub -Idead.letters -oqueue1
MQSeries Q Program by Paul Clarke [ V4.5 Build:Sep 25 2006 ]
Connecting ...connected to 'wmqnode01/hub'.
No more messages.

After using q



We have now demonstrated how to get a message from a spoke to the hub, but we now need to demonstrate how to get a message from one spoke to another spoke via the hub. The example I am going to use is to use two Linux machines. One on 192.168.0.60 and one on 192.168.0.65.

spoke 1 and the hub queue managers will be on 192.168.0.60 (wmqnode01) and spoke 2 will be on 192.168.0.65 (wmgnode02)

Since we already have the hub and spoke q queue managers set, now we must create a queue manager called wmqnode01/spoke on 192.168.0.65.

ssh to mqm@192.168.0.65 and follow these instructions.

..to be continued

Get my WebSphere MQ course here >> http://www.themiddlewareshop.com/products/

Steve Robinson - IBM Champion 2013

About Me

Steve Robinson has been working in IT for over 20 years and has provided solutions for many leading brands around the world. Steve specialises in JEE, DevOps and Thought Leadership.

In January 2013, I was awarded the prestigous 'IBM Champion' accolade.


  • Linked In
  • Twitter
  • About Me
  • Contact Me

Read my books?

IBM WebSphere Application Server 8.0 Administration Guide

IBM WebSphere Application Server 8.0 Administration Guide

WebSphere Application Server 7.0 Administration Guide

WebSphere Application Server 7.0 Administration Guide

Courses

  • WebSphere Courses

Articles

WebSphere Categories

Other Categories