Author |
Message
|
yalmasri |
Posted: Thu Sep 12, 2013 3:04 am Post subject: Sniffing MQ Messages |
|
|
Centurion
Joined: 18 Jun 2008 Posts: 110
|
Hi,
I'm trying to write a simple java program to check random messages on certain queue. For that, I used normal browse to read the messages without actually consuming them. On the other side, we have another application that listens to this queue and consumes the messages normally.
The problem I'm facing is that only when the messages pile up in the queue the browser starts readying them, but if they intermittently come, only the main application reads them, and the browser doesn't receive anything. Is there away to guarantee that all messages are read by the browser?
Here's a snippet of the browsing application:
Code: |
qMgr = new MQQueueManager("QM1");
int openOptions = CMQC.MQOO_BROWSE;
MQQueue myQueue = qMgr.accessQueue("TEST", openOptions, null, null, null);
MQGetMessageOptions gmo = new MQGetMessageOptions();
gmo.options = CMQC.MQGMO_WAIT | CMQC.MQGMO_BROWSE_FIRST;
gmo.waitInterval = CMQC.MQWI_UNLIMITED;
MQMessage myMessage = new MQMessage();
boolean done = false;
do {
try {
myMessage.clearMessage();
myMessage.correlationId = CMQC.MQCI_NONE;
myMessage.messageId = CMQC.MQMI_NONE;
myQueue.get(myMessage, gmo);
String msg = myMessage.readStringOfByteLength(myMessage.getMessageLength());
System.out.println("Browsed message: " + msg);
gmo.options = CMQC.MQGMO_WAIT | CMQC.MQGMO_BROWSE_NEXT;
} catch (MQException ex) {
System.out.println("MQ exception: CC = " + ex.completionCode + " RC = " + ex.reasonCode);
ex.printStackTrace();
done = true;
} catch (java.io.IOException ex) {
System.out.println("Java exception: " + ex);
ex.printStackTrace();
done = true;
}
} while (!done); |
|
|
Back to top |
|
 |
Vitor |
Posted: Thu Sep 12, 2013 4:45 am Post subject: Re: Sniffing MQ Messages |
|
|
 Grand High Poobah
Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA
|
yalmasri wrote: |
I'm trying to write a simple java program to check random messages on certain queue. |
Why? What's the requirement?
yalmasri wrote: |
Is there away to guarantee that all messages are read by the browser? |
There's no way for WMQ to determine that a given message has to be browsed by application A before being made available to application B.
Options available to you include (but are not limited to):
- get your checking program to destructively read the messages and write a copy to a different queue for the "real" program to process
- use mirrorq to copy the message to a different queue for your checking program to process
- use pub/sub to generate multiple copies of the message
- have your checking function incorporated into the real program
It all really depends on what you're really trying to do and why. _________________ Honesty is the best policy.
Insanity is the best defence. |
|
Back to top |
|
 |
mqjeff |
Posted: Thu Sep 12, 2013 5:51 am Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
Also, what you probably want is "a random sample of messages produced", which is *entirely distinct* from "a random sample of messages on the queue".
Not the same thing at all.
It's easy to get a random sample of a set of records in a database table. A queue is not a database table. It's a stream. |
|
Back to top |
|
 |
yalmasri |
Posted: Thu Sep 12, 2013 6:55 am Post subject: Re: Sniffing MQ Messages |
|
|
Centurion
Joined: 18 Jun 2008 Posts: 110
|
Vitor wrote: |
There's no way for WMQ to determine that a given message has to be browsed by application A before being made available to application B.
|
I'm not particularly concerned about the order, but is it really like A or B? Remember that I do not have two applications reading the queue, it's one for reading and another for browsing, which at least should give me one message for the browser every other time, while the reader should get all the messages (after the browser is done with the object lock for its message). Now what happens with me is that the browser doesn't ever receive any message if the reader is not busy with any other message, i.e., only if I have more than one message at a time in the queue the browser get the chance to browse. |
|
Back to top |
|
 |
mqjeff |
Posted: Thu Sep 12, 2013 7:05 am Post subject: Re: Sniffing MQ Messages |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
yalmasri wrote: |
Vitor wrote: |
There's no way for WMQ to determine that a given message has to be browsed by application A before being made available to application B.
|
I'm not particularly concerned about the order, but is it really like A or B? Remember that I do not have two applications reading the queue, it's one for reading and another for browsing, which at least should give me one message for the browser every other time, while the reader should get all the messages (after the browser is done with the object lock for its message). Now what happens with me is that the browser doesn't ever receive any message if the reader is not busy with any other message, i.e., only if I have more than one message at a time in the queue the browser get the chance to browse. |
No.
You have two applications reading the queue.
One is doing so non-destructively.
The other is doing so destructively.
There is absolutely no synchronization between the two apps. MQ provides no mechanism to do this. A message exists on a queue exactly and only as long as it is not destructively read. A message is only available to be read as long as it is not in a unit of work and has not been destructively read.
A queue is not a table. It is a point in time of a stream of data. |
|
Back to top |
|
 |
Vitor |
Posted: Thu Sep 12, 2013 7:07 am Post subject: Re: Sniffing MQ Messages |
|
|
 Grand High Poobah
Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA
|
yalmasri wrote: |
only if I have more than one message at a time in the queue the browser get the chance to browse. |
Because you're doing a browse next & never reset the browse cursor.
I again ask what this is trying to achieve. _________________ Honesty is the best policy.
Insanity is the best defence. |
|
Back to top |
|
 |
yalmasri |
Posted: Thu Sep 12, 2013 8:15 am Post subject: Re: Sniffing MQ Messages |
|
|
Centurion
Joined: 18 Jun 2008 Posts: 110
|
mqjeff wrote: |
There is absolutely no synchronization between the two apps. MQ provides no mechanism to do this. A message exists on a queue exactly and only as long as it is not destructively read. A message is only available to be read as long as it is not in a unit of work and has not been destructively read.
|
Err! I don't know where I left my brain when I said what I said. But what perplexes me is that well, if I have two applications that listen to a queue, why in the world the browser doesn't receive anything at all, no matter which I start first, or how many messages I send! Is it a pure coincidence? |
|
Back to top |
|
 |
yalmasri |
Posted: Thu Sep 12, 2013 8:25 am Post subject: Re: Sniffing MQ Messages |
|
|
Centurion
Joined: 18 Jun 2008 Posts: 110
|
Vitor wrote: |
I again ask what this is trying to achieve. |
I have a legacy production environment that I can't touch, and the inquiry applications running there contain no auditing. What I want is a way to browse the messages in the queue to see which inquiries and how often are they used for reporting purposes |
|
Back to top |
|
 |
Vitor |
Posted: Thu Sep 12, 2013 8:31 am Post subject: Re: Sniffing MQ Messages |
|
|
 Grand High Poobah
Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA
|
yalmasri wrote: |
Vitor wrote: |
I again ask what this is trying to achieve. |
I have a legacy production environment that I can't touch, and the inquiry applications running there contain no auditing. What I want is a way to browse the messages in the queue to see which inquiries and how often are they used for reporting purposes |
Well that's fair enough. _________________ Honesty is the best policy.
Insanity is the best defence. |
|
Back to top |
|
 |
yalmasri |
Posted: Thu Sep 12, 2013 8:38 am Post subject: |
|
|
Centurion
Joined: 18 Jun 2008 Posts: 110
|
hey Vitor, why every time I try to concentrate in the blurred pic you have for yourself I see Tony Blair?! |
|
Back to top |
|
 |
Vitor |
Posted: Thu Sep 12, 2013 8:53 am Post subject: |
|
|
 Grand High Poobah
Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA
|
yalmasri wrote: |
hey Vitor, why every time I try to concentrate in the blurred pic you have for yourself I see Tony Blair?! |
I deny everything  _________________ Honesty is the best policy.
Insanity is the best defence. |
|
Back to top |
|
 |
mqjeff |
Posted: Thu Sep 12, 2013 9:08 am Post subject: Re: Sniffing MQ Messages |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
yalmasri wrote: |
Vitor wrote: |
I again ask what this is trying to achieve. |
I have a legacy production environment that I can't touch, and the inquiry applications running there contain no auditing. What I want is a way to browse the messages in the queue to see which inquiries and how often are they used for reporting purposes |
If you "can't touch" it, then there's nothing you can do...
Depending on what kinds of things you CAN do whilst still "not touching it", you have some different kinds of options.
You basically need an interceptor of some kind, and depending on what you can and can't change, and how the overall system is set up, you have different options for what you can do.
Moving the service application (the one that responds to inquiries) to another queue, and putting a monitoring process in between is a straight-forward option.
As Vitor says, your current attempt is probably failing because you're using BROWSE-NEXT when you should always be using BROWSE_FIRST. And you should be using a blank message id/correl id. Basically, grab the first message at random intervals, rather than trying to grab a random message at routine intervals. |
|
Back to top |
|
 |
yalmasri |
Posted: Thu Sep 12, 2013 10:28 am Post subject: Re: Sniffing MQ Messages |
|
|
Centurion
Joined: 18 Jun 2008 Posts: 110
|
mqjeff wrote: |
As Vitor says, your current attempt is probably failing because you're using BROWSE-NEXT when you should always be using BROWSE_FIRST. And you should be using a blank message id/correl id. Basically, grab the first message at random intervals, rather than trying to grab a random message at routine intervals. |
That logic looks sound. Albeit, I should pick one message at least because I started the first get with BROWSE_FIRST and never get the chance to move the cursor |
|
Back to top |
|
 |
|