Author |
Message
|
md7 |
Posted: Mon Mar 30, 2015 9:24 pm Post subject: Clearing all messages in a queue manager |
|
|
 Apprentice
Joined: 29 Feb 2012 Posts: 49 Location: Sydney.AU
|
I have about 200 or so queues in about 10 queue managers each queue having anywhere between 0 and 5000 messages and was wondering if there was a quicker way of clearing all messages without clearing out each individual queue. This is a Dev / Test environment BTW |
|
Back to top |
|
 |
smdavies99 |
Posted: Mon Mar 30, 2015 9:38 pm Post subject: |
|
|
 Jedi Council
Joined: 10 Feb 2003 Posts: 6076 Location: Somewhere over the Rainbow this side of Never-never land.
|
How about...
endmqm -i QMGR
dltmqm QMGR
then invoke scripts to rebuild the qmgr from scratch.
Drastic? It certainly is but you asked for an alternative didn't you? _________________ WMQ User since 1999
MQSI/WBI/WMB/'Thingy' User since 2002
Linux user since 1995
Every time you reinvent the wheel the more square it gets (anon). If in doubt think and investigate before you ask silly questions. |
|
Back to top |
|
 |
PaulClarke |
Posted: Mon Mar 30, 2015 11:09 pm Post subject: |
|
|
 Grand Master
Joined: 17 Nov 2005 Posts: 1002 Location: New Zealand
|
It would be trivial in MQSCX to write a small script to query the list of queues and issue a CLEAR QLOCAL command for each response.
Cheers,
Paul. _________________ Paul Clarke
MQGem Software
www.mqgem.com |
|
Back to top |
|
 |
smdavies99 |
Posted: Mon Mar 30, 2015 11:49 pm Post subject: |
|
|
 Jedi Council
Joined: 10 Feb 2003 Posts: 6076 Location: Somewhere over the Rainbow this side of Never-never land.
|
PaulClarke wrote: |
It would be trivial in MQSCX to write a small script to query the list of queues and issue a CLEAR QLOCAL command for each response.
Cheers,
Paul. |
That's great but what if a queue was still open?
In a dev env this could well be the case.
{how many times have to left something like RFHUtil open and connected to a queue?} _________________ WMQ User since 1999
MQSI/WBI/WMB/'Thingy' User since 2002
Linux user since 1995
Every time you reinvent the wheel the more square it gets (anon). If in doubt think and investigate before you ask silly questions. |
|
Back to top |
|
 |
PaulClarke |
Posted: Tue Mar 31, 2015 12:09 am Post subject: |
|
|
 Grand Master
Joined: 17 Nov 2005 Posts: 1002 Location: New Zealand
|
I assume, if they are trying to start again, that all test programs and channels etc would be ended.
However, I take your point.....it is annoying that there's no FORCE(YES) parameter on the CLEAR QLOCAL command. Perhaps I should consider adding an =CLEAR QLOCAL to MQSCX to do the 'repeated MQGET' form of a clear queue.
Cheers,
Paul. _________________ Paul Clarke
MQGem Software
www.mqgem.com |
|
Back to top |
|
 |
Andyh |
Posted: Tue Mar 31, 2015 1:02 am Post subject: |
|
|
Master
Joined: 29 Jul 2010 Posts: 239
|
A repeating MQGET won't necessarily remove all messages, for example an uncommitted MQPUT. Stopping connections active against these queues and then purging those queue has attractions, both from a functional and a performance viewpoint. |
|
Back to top |
|
 |
PaulClarke |
Posted: Tue Mar 31, 2015 1:14 am Post subject: |
|
|
 Grand Master
Joined: 17 Nov 2005 Posts: 1002 Location: New Zealand
|
Yes Andy, we all know that ending the applications is preferable but sometimes stopping the applications is not an option (or at least it's awkward). That's why MO71 (and I thought Explorer) has the option to clear a queue through repeated MQGETs.
It's all horses for courses.
Cheers,
Paul. _________________ Paul Clarke
MQGem Software
www.mqgem.com |
|
Back to top |
|
 |
mqjeff |
Posted: Tue Mar 31, 2015 4:34 am Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
PaulClarke wrote: |
(and I thought Explorer) has the option to clear a queue through repeated MQGETs. |
It does, in currently supported releases of MQExplorer. I think it was actually added in the v6 timeframe, but I could be wrong. Certainly well before the v7.1 timeframe. |
|
Back to top |
|
 |
tczielke |
Posted: Tue Mar 31, 2015 4:49 am Post subject: Re: Clearing all messages in a queue manager |
|
|
Guardian
Joined: 08 Jul 2010 Posts: 941 Location: Illinois, USA
|
md7 wrote: |
I have about 200 or so queues in about 10 queue managers each queue having anywhere between 0 and 5000 messages and was wondering if there was a quicker way of clearing all messages without clearing out each individual queue. This is a Dev / Test environment BTW |
I am not sure what the environment here is. If this is distributed, I have found scripting helpful here. Basically, you build a list of queues that you want to drain (i.e. from runmqsc output), and then use an editor (i.e. vi) to alter the output until you have an executable script (i.e. bash script in UNIX) that can run say amqsget commands against all the pertinent queues/queue managers. If you are not familiar with scripting, it is definitely worth the investment to get proficient with it. Once you get proficient with scripting, you could do something like this fairly quickly. _________________ Working with MQ since 2010. |
|
Back to top |
|
 |
RogerLacroix |
Posted: Tue Mar 31, 2015 8:41 am Post subject: |
|
|
 Jedi Knight
Joined: 15 May 2001 Posts: 3264 Location: London, ON Canada
|
MQ Batch Toolkit has a function called ClearQ which first checks the IPPROCS and OPPROCS, if both are zero then it issues the PCF clear q command otherwise it performs the standard MQGET in a loop to clear the queue.
I've written lots of MQ Batch Toolkit (MQBT) scripts for customers to do different things. Here's a Windows script (called ClearQ.bat) that takes 2 parameters: QMgrName and queue name.
i.e.
Code: |
ClearQ.bat MQA1 "TEST.*" |
The script will clear all queues beginning with "TEST." that have a queue depth greater than zero. The Windows script issues 2 MQBT functions to do its thing:
Code: |
@echo off
setlocal
if [%1]==[] echo Queue Manager Profile was not specified && goto Usage
if [%2]==[] echo Queue Name was not specified && goto Usage
cd /D C:\Capitalware\MQBT\
mqbt.exe QLIST -p %1 -k %2 -t L -f qdepth.txt -D
FOR /F "tokens=1,2" %%A in (qdepth.txt) DO (
if %%B GTR 0 (
mqbt.exe ClearQ -p %1 -q %%A
)
)
del qdepth.txt
goto :DONE
:Usage
echo Usage: %0 QMgr_Profile_Name Queue_Name
goto :DONE
:DONE
endlocal |
Regards,
Roger Lacroix
Capitalware Inc. _________________ Capitalware: Transforming tomorrow into today.
Connected to MQ!
Twitter |
|
Back to top |
|
 |
PaulClarke |
Posted: Tue Mar 31, 2015 8:43 am Post subject: |
|
|
 Grand Master
Joined: 17 Nov 2005 Posts: 1002 Location: New Zealand
|
I agree that scripting is useful however scripting that includes parsing the response from MQSC can be a bit of a nightmare. That's one of the reasons why I wrote MQSCX. For example....this would be the script that displays the total number of messages you have on non SYSTEM queues.
Code: |
@total = 0
* Process each non-SYSTEM queue
foreach(DISPLAY QLOCAL(*) CURDEPTH =WHERE(queue NL "SYSTEM.*"))
@total = @total + curdepth
endfor
print "Total number of messages is",@total
|
and this would be the script that would clear all your non-SYSTEM local queues.
Code: |
* Process each non-SYSTEM queue
foreach(DISPLAY QLOCAL(*) CURDEPTH =WHERE(queue NL "SYSTEM.*"))
if (curdepth)
@queue = QUEUE
CLEAR QLOCAL(<@queue>)
endif
endfor
|
As you can see they are both pretty trivial and easy to modify to do other things.
Cheers,
Paul. _________________ Paul Clarke
MQGem Software
www.mqgem.com |
|
Back to top |
|
 |
tczielke |
Posted: Tue Mar 31, 2015 9:02 am Post subject: |
|
|
Guardian
Joined: 08 Jul 2010 Posts: 941 Location: Illinois, USA
|
PaulClarke wrote: |
I agree that scripting is useful however scripting that includes parsing the response from MQSC can be a bit of a nightmare. That's one of the reasons why I wrote MQSCX. For example....this would be the script that displays the total number of messages you have on non SYSTEM queues.
Code: |
@total = 0
* Process each non-SYSTEM queue
foreach(DISPLAY QLOCAL(*) CURDEPTH =WHERE(queue NL "SYSTEM.*"))
@total = @total + curdepth
endfor
print "Total number of messages is",@total
|
and this would be the script that would clear all your non-SYSTEM local queues.
Code: |
* Process each non-SYSTEM queue
foreach(DISPLAY QLOCAL(*) CURDEPTH =WHERE(queue NL "SYSTEM.*"))
if (curdepth)
@queue = QUEUE
CLEAR QLOCAL(<@queue>)
endif
endfor
|
As you can see they are both pretty trivial and easy to modify to do other things.
Cheers,
Paul. |
I do agree with you that your tools are very useful, and I do have it on my to do list to try and get funding to get them in our shop. However, for the sake of the OP, it wasn't too bad to do this with a shell script. The following would work in Linux:
echo "dis ql(*) where (CURDEPTH GE 1)" | runmqsc QM1 | grep -v "SYSTEM." | grep "QUEUE(" | cut -d'(' -f2 | cut -d')' -f1 | while read LineTx; do echo amqsget $LineTx QM1;done
Just paste the output from that long winded command into a file and put a shebang (i.e #!/usr/bin/ksh) at the top, and you have an executable script to drain your queues for a queue manager. _________________ Working with MQ since 2010.
Last edited by tczielke on Tue Mar 31, 2015 9:09 am; edited 1 time in total |
|
Back to top |
|
 |
mqjeff |
Posted: Tue Mar 31, 2015 9:03 am Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
Does amqsget read the entire message these days, or does it still only read the first 100 bytes? |
|
Back to top |
|
 |
tczielke |
Posted: Tue Mar 31, 2015 9:07 am Post subject: |
|
|
Guardian
Joined: 08 Jul 2010 Posts: 941 Location: Illinois, USA
|
mqjeff wrote: |
Does amqsget read the entire message these days, or does it still only read the first 100 bytes? |
Good point. amqsget (on 7.5) can support messages up to 65,536 bytes, but it does treat a truncated message as a failure. So I guess if your queues have larger messages, use your MQ getter program of choice. _________________ Working with MQ since 2010. |
|
Back to top |
|
 |
Vitor |
Posted: Tue Mar 31, 2015 9:14 am Post subject: |
|
|
 Grand High Poobah
Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA
|
tczielke wrote: |
So I guess if your queues have larger messages, use your MQ getter program of choice. |
Or recompile the amqsget sample to a) accept larger messages or b) warn rather than fail if truncating. _________________ Honesty is the best policy.
Insanity is the best defence. |
|
Back to top |
|
 |
|