Work with alias queues

We can define an alias queue to refer indirectly to another queue or topic.

Attention: Distribution lists do not support the use of alias queues that point to topic objects. If an alias queue points to a topic object in a distribution list, IBM MQ returns MQRC_ALIAS_BASE_Q_TYPE_ERROR.

The queue to which an alias queue refers can be any of the following:

An alias queue is not a real queue, but a definition that resolves to a real (or target) queue at run time. The alias queue definition specifies the target queue. When an application makes an MQOPEN call to an alias queue, the queue manager resolves the alias to the target queue name.

An alias queue cannot resolve to another locally defined alias queue. However, an alias queue can resolve to alias queues that are defined elsewhere in clusters of which the local queue manager is a member. See Name resolution for further information.

Alias queues are useful for:

  • Giving different applications different levels of access authorities to the target queue.
  • Allowing different applications to work with the same queue in different ways. (Perhaps we want to assign different default priorities or different default persistence values.)
  • Simplifying maintenance, migration, and workload balancing. (Perhaps we want to change the target queue name without having to change the application, which continues to use the alias.)

For example, assume that 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 TARGQ attribute, we 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

The following command creates an alias queue:
DEFINE QALIAS (MY.ALIAS.QUEUE) TARGET (YELLOW.QUEUE)

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.

If we change the alias definition, we can redirect the MQI calls to another queue. For example:
ALTER QALIAS (MY.ALIAS.QUEUE) TARGET (MAGENTA.QUEUE)

This command redirects MQI calls to another queue, MAGENTA.QUEUE.

We can also use alias queues to make a single queue (the target queue) appear to have different attributes for different applications. You do this by defining two aliases, one for each application. Suppose there are two applications:

  • 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.

The following command defines an alias that is put enabled and get disabled for application ALPHA:

DEFINE QALIAS (ALPHAS.ALIAS.QUEUE) +
TARGET (YELLOW.QUEUE) +
PUT (ENABLED) +
GET (DISABLED)

The following command defines an alias that is put disabled and get enabled for application BETA:

DEFINE QALIAS (BETAS.ALIAS.QUEUE) +
TARGET (YELLOW.QUEUE) +
PUT (DISABLED) +
GET (ENABLED)

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.

We can use the LIKE and REPLACE attributes when you define queue aliases, in the same way that we use these attributes with local queues.


Use other commands with alias queues

We can use the appropriate MQSC commands to display or alter alias queue attributes, or to delete the alias queue object. For example:

Use the DEFINE QALIAS command to display the alias queue's attributes:
DISPLAY QUEUE (ALPHAS.ALIAS.QUEUE)
Use the ALTER QALIAS command to alter the base queue name, to which the alias resolves, where the force option forces the change even if the queue is open:
ALTER QALIAS (ALPHAS.ALIAS.QUEUE) TARGQ(ORANGE.LOCAL.QUEUE) FORCE

Use the DELETE QALIAS command to delete this queue alias:

DELETE QALIAS (ALPHAS.ALIAS.QUEUE)

We cannot delete an alias queue if an application currently has the queue open.

Parent topic: Work with local IBM MQ objects


Related information