ASG
IBM
Zystems
Cressida
Icon
Netflexity
 
  MQSeries.net
Search  Search       Tech Exchange      Education      Certifications      Library      Info Center      SupportPacs      LinkedIn  Search  Search                                                                   FAQ  FAQ   Usergroups  Usergroups
 
Register  ::  Log in Log in to check your private messages
 
RSS Feed - WebSphere MQ Support RSS Feed - Message Broker Support

MQSeries.net Forum Index » IBM MQ Java / JMS » Reading Messages from a Queue with unlimited wait

Post new topic  Reply to topic
 Reading Messages from a Queue with unlimited wait « View previous topic :: View next topic » 
Author Message
scar
PostPosted: Fri Dec 13, 2013 4:27 pm    Post subject: Reading Messages from a Queue with unlimited wait Reply with quote

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
View user's profile Send private message
smdavies99
PostPosted: Fri Dec 13, 2013 10:44 pm    Post subject: Reply with quote

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
View user's profile Send private message
mqjeff
PostPosted: Sun Dec 15, 2013 7:26 am    Post subject: Reply with quote

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
View user's profile Send private message
RogerLacroix
PostPosted: Tue Dec 17, 2013 2:33 pm    Post subject: Re: Reading Messages from a Queue with unlimited wait Reply with quote

Jedi Knight

Joined: 15 May 2001
Posts: 3252
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
View user's profile Send private message Visit poster's website
mqjeff
PostPosted: Tue Dec 17, 2013 2:42 pm    Post subject: Reply with quote

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
View user's profile Send private message
RogerLacroix
PostPosted: Tue Dec 17, 2013 2:56 pm    Post subject: Reply with quote

Jedi Knight

Joined: 15 May 2001
Posts: 3252
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
View user's profile Send private message Visit poster's website
PeterPotkay
PostPosted: Tue Dec 17, 2013 5:56 pm    Post subject: Reply with quote

Poobah

Joined: 15 May 2001
Posts: 7717

I wonder what the backout count is up to on the poison message.....
_________________
Peter Potkay
Keep Calm and MQ On
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic  Reply to topic Page 1 of 1

MQSeries.net Forum Index » IBM MQ Java / JMS » Reading Messages from a Queue with unlimited wait
Jump to:  



You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Protected by Anti-Spam ACP
 
 


Theme by Dustin Baccetti
Powered by phpBB © 2001, 2002 phpBB Group

Copyright © MQSeries.net. All rights reserved.