Working with alias queues on IBM i
This section contains examples of some of the commands that you can use to manage alias queues. All the commands shown are also available using options from the WRKMQMQ command panel.
An alias queue (sometimes known as a queue alias) provides a method of redirecting MQI calls. An alias queue is not a real queue but a definition that resolves to a real queue. The alias queue definition contains a target queue name, which is specified by the TGTQNAME attribute.
When an application specifies an alias queue in an MQI call, the queue manager resolves the real queue name at run time.
For example, an application has been developed to put messages on a queue called
my.alias.queue
. It specifies the name of this queue when it makes an
MQOPEN request and, indirectly, if it puts a message on this queue. The
application is not aware that the queue is an alias queue. For each MQI call using this alias, the
queue manager resolves the real queue name, which could be either a local queue or a remote queue
defined at this queue manager.
By changing the value of the TGTQNAME attribute, you can redirect MQI calls to another queue, possibly on another queue manager. This is useful for maintenance, migration, and load-balancing.
Defining an alias queue
CRTMQMQ QNAME('my.alias.queue') QTYPE(*ALS) TGTQNAME('yellow.queue')
MQMNAME(MYQUEUEMANAGER)
This command redirects MQI calls that specify my.alias.queue
to the queue
yellow.queue
. The command does not create the target queue; the MQI calls fail if
the queue yellow.queue
does not exist at run time.
CHGMQMQ QNAME('my.alias.queue') TGTQNAME('magenta.queue') MQMNAME(MYQUEUEMANAGER)
This command redirects MQI calls to another queue, magenta.queue
.
- Application ALPHA can put messages on
yellow.queue
, but is not allowed to get messages from it. - Application BETA can get messages from
yellow.queue
, but is not allowed to put messages on it.
/* This alias is put enabled and get disabled for application ALPHA */
CRTMQMQ QNAME('alphas.alias.queue') QTYPE(*ALS) TGTQNAME('yellow.queue')
PUTENBL(*YES) GETENBL(*NO) MQMNAME(MYQUEUEMANAGER)
/* This alias is put disabled and get enabled for application BETA */
CRTMQMQ QNAME('betas.alias.queue') QTYPE(*ALS) TGTQNAME('yellow.queue')
PUTENBL(*NO) GETENBL(*YES) MQMNAME(MYQUEUEMANAGER)
ALPHA uses the queue name alphas.alias.queue
in its MQI calls; BETA uses the
queue name betas.alias.queue
. They both access the same queue, but in different
ways.
You can use the REPLACE *YES attribute when you define alias queues, in the same way that you use these attributes with local queues.
Using other commands with alias queues
* Display the alias queue's attributes */
DSPMQMQ QNAME('alphas.alias.queue') MQMNAME(MYQUEUEMANAGER)
/* ALTER the base queue name, to which the alias resolves. */
/* FORCE = Force the change even if the queue is open. */
CHQMQMQ QNAME('alphas.alias.queue') TGTQNAME('orange.local.queue') FORCE(*YES)
MQMNAME(MYQUEUEMANAGER)