Suganthan Raj
Suganthan Raj

Reputation: 2424

How to remove all queues from cluster in queue manager in IBM MQ using linux?

I have used the below command to remove all queues in cluster in the queue manager

echo "ALTER QLOCAL(*) CLUSTER('') CLUSNL('')" | runmqsc ${qmgr}.

I have got the error as 1 : ALTER QLOCAL(*) CLUSTER('') CLUSNL('') AMQ8147: WebSphere MQ object * not found. One MQSC command read. No commands have a syntax error. One valid MQSC command could not be processed.

My need is to remove all queues which are in cluster in the queue manager. Thanks in advance

Upvotes: 3

Views: 2379

Answers (1)

Rob Parker
Rob Parker

Reputation: 774

You can't use the wildcard character (*) when altering MQ Objects. Instead you have to specify the exact object you want to alter and that object has to exist. This is the reason your command fails (as it is looking for an object called * which does not exist.

If you want to change multiple objects you have to either use a third party tool which supports this or you have to do it programmatically. If you opt to do it programmatically your program has to do the following

  1. Query your Queue Manager for the objects you want to alter. This could be done using echo "DISPLAY QLOCAL(*) CLUSTER(<cluster name>)" | runmqsc -e <QMNAME>

The above command should only display Queues in the specified cluster and the -e option will mean you won't see 1 : DISPLAY QLOCAL(*) CLUSTER(<cluster name>) in the output. However, if the command returns any objects you will get output similar to and you will get a return code of 0:

5724-H72 (C) Copyright IBM Corp. 1994, 2016.
Starting MQSC for queue manager ROB.


AMQ8409: Display Queue details.
   QUEUE(LOCAL)                            TYPE(QLOCAL)
   CLUSTER(<cluster name>)
AMQ8409: Display Queue details.
   QUEUE(QL)                               TYPE(QLOCAL)
   CLUSTER(<cluster name>)

If the command fails to find any Queues however you will see the following error and you will get a return code of 0:

5724-H72 (C) Copyright IBM Corp. 1994, 2015.
Starting MQSC for queue manager QMROB.


AMQ8147: WebSphere MQ object * not found.
One MQSC command read.
No commands have a syntax error.
One valid MQSC command could not be processed.

So before you can pipe the Queue names back into runmqsc you have to get the raw Queue names

  1. Trim the output to remove everything except for the Q name. This can be done in a number of ways but i would personally use grep and sed . First we only want the lines that have QUEUE on them so we use grep to remove everything except for the round brackets (and it's contents) after QUEUE. Then we use sed to remove the round brackets. You end up with something like this:

    grep -o -P "(?<=QUEUE)(.+?)" | sed -e 's/[(|)]//g

If we add that onto our previous command we get:

echo "DISPLAY QLOCAL(*) CLUSTER(<cluster name>)" | runmqsc -e <QMNAME> | grep -o -P "(?<=QUEUE)\(.+?\)" | sed -e 's/[(|)]//g

which gives us the output:

LOCAL
QL
  1. Finally we want to push this back into runmqsc to alter all of the Queues as needed, we can do this using xargs. We want to push it through xargs twice as the first one will make sure each Queue name goes through as an individual command which is executed by the second one:

    xargs -n 1 | xargs -I {} echo "ALTER QUEUE({}) CLUSTER('') CLUSNL('')" | runmqsc <QM Name>

Putting the whole thing together should get you something like:

echo "DISPLAY QLOCAL(*) CLUSTER(<cluster name>)" | runmqsc -e <QMNAME> | grep -o -P "(?<=QUEUE)\(.+?\)" | sed -e 's/[(|)]//g | xargs -n 1 | xargs -I {} echo "ALTER QUEUE({}) CLUSTER('') CLUSNL('')" | runmqsc <QM Name>

Of course the above is just an example of how you could do it in one line, however it would be much better to do it via a shell script where you can add checks in between each step to make sure you're not about to do something to your Queues you don't want to.

While testing as well you could use the -v flag on runmqsc as this will verify the commands without performing the actions - So you can see the output and runmqsc will tell you if there are any problems, without doing it immediately.

Upvotes: 2

Related Questions