How to Create and Empty a NULL Queue in a Queue Manager

The other day, an old consulting colleague emailed me with an interesting question.

A client of mine has an application with no source code that sends messages to the MQ queue specified in a property file. They don’t want this message to be received by the message listener any longer. Code change is not an option. Does MQ have have a “null” queue which would cause the messages to disappear right away?

Without the source code, the number of options are limited. Obviously, if you had the source code, you could simply comment out the MQ code in the program. But in this case, life is not so simple.

My first thought was to have the application use an invalid queue name. This would cause the application to receive Reason Code ‘2085’ (Unknown Object Name). The only problem is that the application needs to continue running rather than error exit.

Then I thought, if Linux/Unix can have /dev/null and Windows has NUL for commands and/or scripts then why shouldn’t MQ have a NULL.Q for throw away messages. This is really easy to implement in MQ with a simple piece of C code called ‘EmptyQ’.

Step #1: Go get the EmptyQ program from my web site at: https://www.capitalware.com/mq_code_c.html

Note: The EmptyQ program is a simple program that retrieves every message from a particular queue and does nothing with the messages (throws the data away). You will need to compile and link the EmptyQ program for the particular platform you require it for.

Step #2: Define the local queue called ‘NULL.Q’ in the queue manager. Use runmqsc and issue the following command:

DEFINE QLOCAL(NULL.Q)

Step #3: Define the queue manager service to run the EmptyQ program. Use runmqsc and issue the following command on Windows:

DEFINE SERVICE(EMPTY_NULL.Q) +
       DESCR('Continuously empty the NULL.Q') +
       STARTCMD('C:\apps\EmptyQ\emptyq.exe') +
       STARTARG('NULL.Q +QMNAME+') +
       STOPCMD(' ') +
       STOPARG(' ') +
       STDOUT('C:\apps\EmptyQ\stdout.log') +
       STDERR('C:\apps\EmptyQ\stderr.log') +
       CONTROL(STARTONLY) +
       SERVTYPE(SERVER) +
       REPLACE

For Linux/Unix use the following command:

DEFINE SERVICE(EMPTY_NULL.Q) +
       DESCR('Continuously empty the NULL.Q') +
       STARTCMD('/apps/EmptyQ/emptyq') +
       STARTARG('NULL.Q +QMNAME+') +
       STOPCMD(' ') +
       STOPARG(' ') +
       STDOUT('/apps/EmptyQ/stdout.log') +
       STDERR('/apps/EmptyQ/stderr.log') +
       CONTROL(STARTONLY) +
       SERVTYPE(SERVER) +
       REPLACE

Note: There is no stop command. The MQGET is coded with MQGMO_FAIL_IF_QUIESCING, hence, when the queue manager is shutting down, the EmptyQ program will receive the appropriate Reason Code and terminate.

Step #4: Start the service with the following command on Windows:

START SERVICE(EMPTY_NULL.Q)

You have now created a ‘NULL.Q’ queue and any message put to this queue will be immediately consumed. The service has been setup so that each time the queue manager is restarted, the service will immediately start consuming messages.

Regards,
Roger Lacroix
Capitalware Inc.

———————-

All,

Paul Clarke says the following MQSC command will also do the job:

DEFINE TOPIC(NULLTOPIC) TOPICSTR(‘.NULL.’) SUB(DISABLED)
DEFINE QALIAS(NULLQ) TARGTYPE(TOPIC) TARGET(NULLTOPIC)

Regards,
Roger Lacroix
Capitalware Inc.

This entry was posted in Capitalware, IBM i (OS/400), IBM MQ, Linux, Open Source, Programming, Unix, Windows, z/OS.

One Response to How to Create and Empty a NULL Queue in a Queue Manager