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 » Is this way of listening for JMS messages inefficient?

Post new topic  Reply to topic
 Is this way of listening for JMS messages inefficient? « View previous topic :: View next topic » 
Author Message
smalltalk2k
PostPosted: Tue May 03, 2005 5:52 am    Post subject: Is this way of listening for JMS messages inefficient? Reply with quote

Novice

Joined: 03 May 2005
Posts: 10

The message class below is javax.jms.Message
The reciever is javax.jms.QueueReceiver.

Is this way of reading a Queue grossly inefficient for a system that would recieve roughly 40,000 straight mq messages in a 24 hour period. I'm asking in reference to the reciever.recieve(1) and the while loop. The system.out message of course would be removed.

The messages would be about 40 characters in length.


Code:
while (!isStopped()) {
            Message m = receiver.receive(1);
            if (m != null) {
               if (m instanceof TextMessage) {
                  message = (TextMessage) m;
                  System.out.println(
                     Messages.getString("JMS_TEST.MESSAGE_RECIEVED_PREFIX") + message.getText()); //$NON-NLS-1$
                  if (message.getText().equalsIgnoreCase(Messages.getString("JMS_TEST.STOP")) //$NON-NLS-1$
                     || message.getText().equalsIgnoreCase(Messages.getString("JMS_TEST.EXIT"))) { //$NON-NLS-1$
                     stopLoop();
                  }
               } else {
                  System.out.println(
                     Messages.getString("JMS_TEST.MESSAGE_NON_TEXT_RECIEVED")); //$NON-NLS-1$
                  stopLoop();
               }
            }
         }
Back to top
View user's profile Send private message
fjb_saper
PostPosted: Tue May 03, 2005 11:48 am    Post subject: Reply with quote

Grand High Poobah

Joined: 18 Nov 2003
Posts: 20756
Location: LI,NY

I would like to see a MessageListener pattern applied here.
Remember as well to add a ConnectionErrorListener.

Enjoy
Back to top
View user's profile Send private message Send e-mail
dwitherspoon
PostPosted: Tue May 24, 2005 12:18 pm    Post subject: Caveat... Reply with quote

Acolyte

Joined: 09 Dec 2003
Posts: 59

A caveat to this is that if you want a graceful shutdown, you may have to resort to your first idea. That way you can be in a while (!stop) loop, and inside you do receive(x). Then every x millis you can be checking to see if you should gracefully stop.

This is what I do, but i have x set to 15 seconds...saying that I'm willing to wait 15 seconds (7 on average) for a graceful shutdown to happen.
_________________
Good...Fast...Cheap. Choose any two.
Back to top
View user's profile Send private message
fjb_saper
PostPosted: Tue May 24, 2005 12:25 pm    Post subject: Reply with quote

Grand High Poobah

Joined: 18 Nov 2003
Posts: 20756
Location: LI,NY

You can also do a gracefull shutdown with a message listener.

a) stop the connection
b) set the MessageListener to null on the Consumer
c) set the ExceptionListener to null
d) release all JMS resources

Enjoy
Back to top
View user's profile Send private message Send e-mail
dwitherspoon
PostPosted: Tue May 24, 2005 12:31 pm    Post subject: Reply with quote

Acolyte

Joined: 09 Dec 2003
Posts: 59

I actually had some trouble doing this because I was trying to shut things down from one thread while the listener thread was trying to process a message. I probably screwed it up because I was under the gun, so I punted and went back to the loop thing.
_________________
Good...Fast...Cheap. Choose any two.
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 » Is this way of listening for JMS messages inefficient?
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.