I don’t write about MQ Batch Toolkit (MQBT) very often, so when I got an MQBT support email today, I thought that the question and answer would make a good blog item.
Question:
In MQ Batch Toolkit, what command can be issued, for exporting messages to a file, to retrieve all messages on a queue except in the case where there are more than 1000 messages (and cannot wait more than 30 seconds for the MQGET). i.e. Retrieve up to 1000 messages at any given time without waiting a long period of time for more messages to arrive. The reason for the 1000 message limit, is to limit network traffic in any given period of time.
Current, MQBT Export command used:
mqbt.exe Export -p {profile} -q {queue_name} -f {filename} -c {num_files} -C -D
Answer:
When the ‘-c’ parameter is used in the Export function then MQBT will issue MQGET with unlimited wait. If you use ‘-c 1000’ then MQBT will wait until it receives 1000 messages. MQBT is attempting to accomplish the task of retrieving 1000 messages and it could wait for many minutes or even hours.
The simplest solution is to write a script to first check the queue depth using the MQBT’s QDepth function and then perform the Export function based on whether or not the queue depth is above a particular value
@echo off setlocal if [%1]==[] echo Queue Manager Profile was not specified && goto Usage if [%2]==[] echo Queue Name was not specified && goto Usage if [%3]==[] echo Output filename was not specified && goto Usage SET /A MAX_MSG=1000 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 '%%A'=='%2' ( if %%B GTR %MAX_MSG% ( mqbt.exe Export -p %1 -q %2 -f %3 -c %MAX_MSG% -C -D ) else ( mqbt.exe Export -p %1 -q %2 -f %3 -C -D ) ) ) del qdepth.txt goto :DONE :Usage echo Usage: %0 Profile_Name Queue_Name Ouput_File_Name goto :DONE :DONE endlocal
Breakdown of the script:
The script expects 3 parameters:
– Queue Manager Profile
– Queue Name
– Output file name
Line # 8 is where you set the maximum number of messages to be retrieved.
Line # 11 issues the QDepth function to retrieve the depth of the queue and writes it to a file called ‘qdepth.txt’.
Line # 12 loops over the file ‘qdepth.txt’ and tokenizes the values of each line.
Line # 14 checks that it has the correct queue name.
Line # 15 checks if current queue depth is greater than the maximum queue depth,
– if true then issue Export function with ‘-c’ keyword to limit the number of messages retrieved
– else issue Export function without ‘-c’ keyword to retrieve all of the messages on the queue.
Hopefully, this blog posting will give people ideas on how to extend the use of MQBT.
Regards,
Roger Lacroix
Capitalware Inc.