Author |
Message
|
adivyayadav |
Posted: Mon May 16, 2011 4:10 am Post subject: Clearing a particular Queue |
|
|
 Novice
Joined: 09 Mar 2011 Posts: 10
|
I am writing a program to read all the messages from a given Queue.
==============================================
public static void clearQueue(String queueName) throws Exception {
try {
MQMessage mqMessage = new MQMessage();
MQGetMessageOptions gmo = new MQGetMessageOptions();
gmo.options= MQC.MQGMO_NO_SYNCPOINT; //Set no sync point
gmo.options= MQC.MQGMO_CONVERT; //Handles ASCII/EBCDIC
gmo.options= MQC.MQGMO_WAIT;//Wait until message arrives
gmo.waitInterval= 3000;
MQQueue queueHandle = qMgr.accessQueue("Testing", MQ_Q_OPEN_OPTIONS);
int queueDepth = queueHandle.getCurrentDepth();
if (queueDepth > 0) {
System.out.println("Queue depth = "+ queueDepth);
for (int i = 0; i < queueDepth; i++) {
queueHandle.get(mqMessage,gmo);
System.out.println("\n"+mqMessage.readLine());
gmo.options = MQC.MQGMO_MSG_UNDER_CURSOR;
gmo.options = MQC.MQGMO_BROWSE_NEXT;
}
return;
}
} catch (Exception e) {
}
}
It gets the first message and then gives an error
[color=red][b]MQJE001: Completion Code 2, Reason 2033[/b][/color]
Can any help?? |
|
Back to top |
|
 |
joebuckeye |
Posted: Mon May 16, 2011 4:51 am Post subject: |
|
|
 Partisan
Joined: 24 Aug 2007 Posts: 365 Location: Columbus, OH
|
And did you look up what reason code 2033 means?
When developing MQ apps you need to learn to look up what these reason codes mean.
Once you know what the reason codes mean you can start to figure out how to solve your problem.
If you are on a UNIX like server you should try the command: mqrc <reason code> |
|
Back to top |
|
 |
zpat |
Posted: Mon May 16, 2011 5:09 am Post subject: |
|
|
 Jedi Council
Joined: 19 May 2001 Posts: 5866 Location: UK
|
Don't loop for the queue depth. Messages may arrive or leave in the meantime.
Simply loop until 2033 is received. This is a NORMAL return code and means the queue is empty.
You won't clear a queue by browsing the messages!
Just open the queue for input, get the messages until 2033 then close the queue.
Forget about browse, cursor, wait - all are irrelevant for simply removing messages. |
|
Back to top |
|
 |
PeterPotkay |
Posted: Mon May 16, 2011 6:49 am Post subject: |
|
|
 Poobah
Joined: 15 May 2001 Posts: 7722
|
zpat wrote: |
Simply loop until 2033 is received. This is a NORMAL return code and means the queue is empty. |
More precisely, it means there are no messages available that meet your selection criteria. There might be some available messages on the queue and you can get a 2033 if you are looking for a specific message. There may be no available messages even though the q depth is > 0 because they may be expired messages or uncommitted messages. _________________ Peter Potkay
Keep Calm and MQ On |
|
Back to top |
|
 |
mqjeff |
Posted: Mon May 16, 2011 7:08 am Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
PeterPotkay wrote: |
zpat wrote: |
Simply loop until 2033 is received. This is a NORMAL return code and means the queue is empty. |
More precisely, it means there are no messages available that meet your selection criteria. There might be some available messages on the queue and you can get a 2033 if you are looking for a specific message. There may be no available messages even though the q depth is > 0 because they may be expired messages or uncommitted messages. |
In particular, the MQMessage object is altered by the get operation. |
|
Back to top |
|
 |
zpat |
Posted: Mon May 16, 2011 7:30 am Post subject: |
|
|
 Jedi Council
Joined: 19 May 2001 Posts: 5866 Location: UK
|
All that may be true but a little advanced bearing in mind the apparent basic confusion between reading/browsing and clearing the queue. |
|
Back to top |
|
 |
|