Monday 22 September 2014

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



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.

















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.



 

No comments:

Post a Comment