Author |
Message
|
scar |
Posted: Fri Dec 13, 2013 4:27 pm Post subject: Reading Messages from a Queue with unlimited wait |
|
|
Centurion
Joined: 23 Jun 2004 Posts: 145
|
We are trying to read messages from a queue using a while loop.
While (true)
{
int openInputOptions = CMQC.MQOO_INPUT_AS_Q_DEF+CMQC.MQOO_INQUIRE
+ CMQC.MQOO_OUTPUT+ CMQC.MQOO_SET;
mqqueue = mqQueueManager.accessQueue(queue, openInputOptions, null,null,null);
MQGetMessageOptions gmo = new MQGetMessageOptions();
gmo.options = CMQC.MQGMO_WAIT | CMQC.MQGMO_SYNCPOINT;
gmo.waitInterval = CMQC.MQWI_UNLIMITED;//Infinite wait time
queue.get(message, gmo);
//Read the message and process it
}
I was under the impression that the process will wait for an unlimited time until a message arrives on the queue.
In our case its going through the while loop non-stop. Its taking a hit on the CPU time.
Am I missing something here please ? |
|
Back to top |
|
 |
smdavies99 |
Posted: Fri Dec 13, 2013 10:44 pm Post subject: |
|
|
 Jedi Council
Joined: 10 Feb 2003 Posts: 6076 Location: Somewhere over the Rainbow this side of Never-never land.
|
Look at the samples provided with WMQ (especially amqsget). The sample uses a 15 second wait time. You can easily change this to give you a zero (i.e. infinite) wait. _________________ 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 |
|
 |
mqjeff |
Posted: Sun Dec 15, 2013 7:26 am Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
smdavies99 wrote: |
Look at the samples provided with WMQ (especially amqsget). The sample uses a 15 second wait time. You can easily change this to give you a zero (i.e. infinite) wait. |
I agree that the code posted is not in a [c o d e ] block, but that doesn't mean it's not there... |
|
Back to top |
|
 |
RogerLacroix |
Posted: Tue Dec 17, 2013 2:33 pm Post subject: Re: Reading Messages from a Queue with unlimited wait |
|
|
 Jedi Knight
Joined: 15 May 2001 Posts: 3264 Location: London, ON Canada
|
smdavies99 wrote: |
You can easily change this to give you a zero (i.e. infinite) wait. |
What in the world are you talking about?
From cmqc.h:
Code: |
/* Wait Interval */
#define MQWI_UNLIMITED (-1) |
scar, I wouldn't say that your code is garbage but pretty dare close. You want to read (get) messages from the queue so you open it for input AND output AND setting the MQMD values. Why? Or you figured, why not throw everything at the wall?
Also, you do NOT open a queue in a loop. You do it outside of the loop.
Anyway, here is code that will read (get) messages from a queue and wait forever.
Code: |
int openInputOptions = CMQC.MQOO_INPUT_AS_Q_DEF + CMQC.MQOO_INQUIRE + CMQC.MQOO_FAIL_IF_QUIESCING;;
mqqueue = mqQueueManager.accessQueue(queue, openInputOptions, null,null,null);
MQGetMessageOptions gmo = new MQGetMessageOptions();
gmo.options = CMQC.MQGMO_WAIT + CMQC.MQGMO_SYNCPOINT + CMQC.MQGMO_FAIL_IF_QUIESCING;
gmo.waitInterval = CMQC.MQWI_UNLIMITED;//Infinite wait time
MQMessage message;
While (true)
{
message = new MQMessage();
queue.get(message, gmo);
//Read the message and process it
} |
If you are lost then read the MQ InfoCenter or take an MQ introduction to MQ course. Also, I have posted hundreds of MQ sample programs on my web site including 34 just on Java and MQ.
http://www.capitalware.biz/mq_code_java.html
Regards,
Roger Lacroix
Capitalware Inc. _________________ Capitalware: Transforming tomorrow into today.
Connected to MQ!
Twitter |
|
Back to top |
|
 |
mqjeff |
Posted: Tue Dec 17, 2013 2:42 pm Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
None of this would explain why it seems that the code that correctly specified an unlimited wait time was actually returning from the GET without waiting forever.
Of course, no data has been provided about what RC the get provides when it returns... |
|
Back to top |
|
 |
RogerLacroix |
Posted: Tue Dec 17, 2013 2:56 pm Post subject: |
|
|
 Jedi Knight
Joined: 15 May 2001 Posts: 3264 Location: London, ON Canada
|
Garbage in, garbage out. If you do not catch exceptions then the JVM will propagate it to a higher and higher routine then until a general Exception clause catches it or it causes the JVM to terminate (thrown right out of the program).
Besides, his description does not match the code. He is implying that get method is returning and not throwing an exception. The only way for this to happen is if the waitInterval is a small positive value.
Regards,
Roger Lacroix
Capitalware Inc. _________________ Capitalware: Transforming tomorrow into today.
Connected to MQ!
Twitter |
|
Back to top |
|
 |
PeterPotkay |
Posted: Tue Dec 17, 2013 5:56 pm Post subject: |
|
|
 Poobah
Joined: 15 May 2001 Posts: 7722
|
I wonder what the backout count is up to on the poison message..... _________________ Peter Potkay
Keep Calm and MQ On |
|
Back to top |
|
 |
|