Author |
Message
|
wmquser |
Posted: Mon Apr 26, 2010 10:27 am Post subject: MQ Browse all |
|
|
Apprentice
Joined: 20 Aug 2008 Posts: 32
|
Hi,
My requirement is to browse all the message from the queue and write to a file (message should not be deleted from the queue). I opened the queue with MQC.MQOO_INPUT_SHARED | MQC.MQOO_INQUIRE | MQC.MQOO_BROWSE. I did a mqget with MQC.MQGMO_BROWSE_FIRST for the first mqget call and for the subsequent call I used MQC.MQGMO_BROWSE_NEXT. But though there are 4 messages in the queue, the browse next fails with 2033 (no message available in the queue).
The code is below
MQQueue queue = null;
int dataLength = 0;
byte[] msg = null;
String[] allMsg = new String[10];
boolean notLastMsg = true;
int i=0;
try {
System.out.println("in try ...");
com.ibm.mq.MQGetMessageOptions l_gmo = new com.ibm.mq.MQGetMessageOptions();
MQMessage message = new MQMessage();
int l_getOptions = MQC.MQOO_BROWSE | MQC.MQOO_INPUT_SHARED;
queue = manager.accessQueue(queueName, l_getOptions);
l_gmo.options = MQC.MQGMO_BROWSE_FIRST;
do {
queue.get(message, l_gmo);
System.out.println("in loop after get:" + i );
dataLength = message.getDataLength();
msg = new byte[dataLength];
message.readFully(msg);
message.clearMessage();
allMsg[i] = new String(msg);
System.out.println("in loop browse msg:" +allMsg[i]);
l_gmo.options = MQC.MQGMO_BROWSE_NEXT;
i = i++;
} while (notLastMsg);
System.out.println("all msg " + allMsg);
} catch (MQException e) {
System.out.println("error" + e);
}
Could you please advise on how to fix this.
Thanks |
|
Back to top |
|
 |
fjb_saper |
Posted: Mon Apr 26, 2010 10:40 am Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
There is nothing to fix.
Uncommitted messages are not in a gettable state but count in the queue depth.
Did you try looking at the messages with a tool like MO71 or rfhutil(c)?
How many messages are in a gettable state on the queue?
You might want to clear the msgId and correlId fields of the MQMD for each iteration in the loop...  _________________ MQ & Broker admin |
|
Back to top |
|
 |
wmquser |
Posted: Mon Apr 26, 2010 6:17 pm Post subject: |
|
|
Apprentice
Joined: 20 Aug 2008 Posts: 32
|
There are no uncommitted messages in the queue. I could able to see all the messages in the MQVisual edit. I put message in the queue using the MQ explorer. I dont use msgid or correld to get / browse from the queue. |
|
Back to top |
|
 |
fjb_saper |
Posted: Mon Apr 26, 2010 7:48 pm Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
wmquser wrote: |
There are no uncommitted messages in the queue. I could able to see all the messages in the MQVisual edit. I put message in the queue using the MQ explorer. I dont use msgid or correld to get / browse from the queue. |
You do if you don't clear the fields (set then to MQID_NONE and MQCI_NONE.
This is why after each MQGET (with browse) you must clear them before the next MQGET.
Have fun  _________________ MQ & Broker admin |
|
Back to top |
|
 |
wmquser |
Posted: Tue Apr 27, 2010 12:52 am Post subject: |
|
|
Apprentice
Joined: 20 Aug 2008 Posts: 32
|
|
Back to top |
|
 |
zpat |
Posted: Tue Apr 27, 2010 2:04 am Post subject: |
|
|
 Jedi Council
Joined: 19 May 2001 Posts: 5866 Location: UK
|
Browsing is not a good idea for business applications since it may result in duplicated data, and it breaks the once and once only message delivery paradigm that is a hallmark of WMQ. Similarly using files to deliver data to applications is also a bad idea for a number of integrity reasons.
There is rarely a good reason to be coding browse when there are plenty of free tools to view queue contents, and/or save them to files, already. Of course you may have a good reason to be doing this? |
|
Back to top |
|
 |
bob_buxton |
Posted: Tue Apr 27, 2010 11:59 am Post subject: |
|
|
 Master
Joined: 23 Aug 2001 Posts: 266 Location: England
|
Browse is particularly dangerous if messages are being put and got from the queue while the browse is in operation, there is a real possibility of missing messages. For example if a high priority message arrives on the queue after the browse cursor has moved onto lower priority messages. Uncommitted puts and rolled back gets can also be skipped.
If you do need to browse an active queue you should look at the message marking options that were introduced in MQ v7. _________________ Bob Buxton
Ex-Websphere MQ Development |
|
Back to top |
|
 |
fatherjack |
Posted: Tue Apr 27, 2010 11:50 pm Post subject: |
|
|
 Knight
Joined: 14 Apr 2010 Posts: 522 Location: Craggy Island
|
zpat wrote: |
Browsing is not a good idea for business applications |
Surely it depends on what the business applications requirements are, what they are doing and what they are using the messages for etc. |
|
Back to top |
|
 |
zpat |
Posted: Wed Apr 28, 2010 2:59 am Post subject: |
|
|
 Jedi Council
Joined: 19 May 2001 Posts: 5866 Location: UK
|
Not really. MQ is designed for one time, transactionally safe delivery of messages. Browsing is there for system utilities to use, not for business application use.
I have seen MQ mis-used by applications of course, I just don't recommend it. You might as well use something that doesn't offer the same advantages and save the license fee.
Although I have never seen a sensible use for browsing in an application (as opposed to in a trigger monitor, message viewer etc) in the 15 years that I have worked with MQ, if you known of one please share it with us.
The only one I can think of would be to takes samples of messages, not caring if the samples were complete or not. This would seem unlikely for a business application.
If you need to duplicate messages, just write an application to do one MQGET and two MQPUTs (to different queues) under a single unit of work (syncpoint). WMB can be used for this as well. That way the integrity of the message delivery is maintained. |
|
Back to top |
|
 |
fatherjack |
Posted: Wed Apr 28, 2010 4:38 am Post subject: |
|
|
 Knight
Joined: 14 Apr 2010 Posts: 522 Location: Craggy Island
|
zpat wrote: |
Browsing is there for system utilities to use, not for business application use. |
Don't recall reading that in Harry Harris's MQI book.
And if it's for system utilities only why does IBM provide a Browse Only tick box on the MQGet node in WMB.
I do agree that it is more suited to system utilities but there are always exceptions to the rule.
zpat wrote: |
I have seen MQ mis-used by applications of course, I just don't recommend it. |
Me too. And more often than not I agree there are indeed better ways of doing things.
zpat wrote: |
Although I have never seen a sensible use for browsing in an application in the 15 years that I have worked with MQ |
As you've worked with MQ for 15 years you'll know thats lots of the excellent functionality (e.g. pub/sub, message groups) was not in the product in those early days so maybe some of us had to do things ourselves. And maybe that included browsing messages. |
|
Back to top |
|
 |
Vitor |
Posted: Wed Apr 28, 2010 5:21 am Post subject: |
|
|
 Grand High Poobah
Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA
|
fatherjack wrote: |
And if it's for system utilities only why does IBM provide a Browse Only tick box on the MQGet node in WMB. |
For the same reason WMQ allows you to set your own message ids & correl ids. In 99.9% of cases it's a mind-numbingly stupid idea but there's the 0.1% of cases you need to do it. So in WMQ & WMB (the MQGet node) all the facilities available are provided.
fatherjack wrote: |
I do agree that it is more suited to system utilities but there are always exceptions to the rule. |
And nearly all the times I've seen browse being used it wasn't an exception just a really bad design. For instance: a business application did a browse, captured the content & ids in a file, file was used input to a 2nd app where the content drove business processing and a variation of the 1st app browsed for the messge id and did a destructive get under cursor. Why they couldn't use a destructive get in the business process but had to do a browse? They wanted to be sure messages would only be removed if the business process worked.
zpat wrote: |
I have seen MQ mis-used by applications of course, I just don't recommend it. |
fatherjack wrote: |
zpat wrote: |
Although I have never seen a sensible use for browsing in an application in the 15 years that I have worked with MQ |
As you've worked with MQ for 15 years you'll know thats lots of the excellent functionality (e.g. pub/sub, message groups) was not in the product in those early days so maybe some of us had to do things ourselves. And maybe that included browsing messages. |
[/quote]
I've worked with MQ for nearly as long. And browsing messages was never necessary & never a good idea for same reasons you should work with a result set from a database and not use a cursor. _________________ Honesty is the best policy.
Insanity is the best defence. |
|
Back to top |
|
 |
fatherjack |
Posted: Wed Apr 28, 2010 5:32 am Post subject: |
|
|
 Knight
Joined: 14 Apr 2010 Posts: 522 Location: Craggy Island
|
Sorry for being pedantic but ...
Vitor wrote: |
there's the 0.1% of cases you need to do it. |
contradicts ....
Vitor wrote: |
never necessary & never a good idea |
But I get your point.
I think we are all pretty well in agreement that there are nearly always better designs that remove the need for business apps to browse messages.
But there are those 0.1% of cases. |
|
Back to top |
|
 |
Vitor |
Posted: Wed Apr 28, 2010 6:06 am Post subject: |
|
|
 Grand High Poobah
Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA
|
fatherjack wrote: |
But there are those 0.1% of cases. |
And (closing the circle) in each of those cases you need to be aware of the restrictions & potential problems you will encounter such as those the OP did. _________________ Honesty is the best policy.
Insanity is the best defence. |
|
Back to top |
|
 |
zpat |
Posted: Wed Apr 28, 2010 7:13 am Post subject: |
|
|
 Jedi Council
Joined: 19 May 2001 Posts: 5866 Location: UK
|
You need to remember most questions here are posted by inexperienced people (and your profile showed only 20 or so posts).
I will give a quick answer that is correct 99.9% of the time because otherwise it will confuse these people (and also I am not paid to do this).
Besides, if someone can come up with a reason why I am not correct it's fine, the point of a BB is to discuss things.
As always - keeping designs simple and mainstream is a good idea. There are many product features that are very rarely needed - and usually only then by specialised utilities written by experts.
Sadly I have seen programmers using browse for entirely the wrong reasons! |
|
Back to top |
|
 |
PeterPotkay |
Posted: Wed Apr 28, 2010 9:34 am Post subject: |
|
|
 Poobah
Joined: 15 May 2001 Posts: 7722
|
# of posts is no guarantee of MQ knowledge (or lack there of).
I would say Browse is misused more often than not. Just like Trigger Every.
When Browse is being correctly used by the app, odds are MQ is incorrectly being used - i.e. its probably data that belongs in a DB. _________________ Peter Potkay
Keep Calm and MQ On |
|
Back to top |
|
 |
|