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 » MQSERIES/JMS/JAVA listeners and not running under WAS

Post new topic  Reply to topic
 MQSERIES/JMS/JAVA listeners and not running under WAS « View previous topic :: View next topic » 
Author Message
kiran_tala
PostPosted: Fri Jul 16, 2004 12:49 pm    Post subject: MQSERIES/JMS/JAVA listeners and not running under WAS Reply with quote

Novice

Joined: 16 Jul 2004
Posts: 14

We are doing the XML messaging with MQSeries/JMS/JAVA and Application server facility. This application is a standalone JAVA application running under UNIX and this is not running under WAS. We have a listener set up on that queue and we start this in the evening and Its job is get all the messages one by one and update our database. We are starting this listener thru a UNIX shell script. Once all the messages are done it should get stopped. Right now it will run for 15 minutes and after that it gets stopped. We want to stop this listener automatically once the processing is done on all messages are done.
Any Ideas how to do this?
Back to top
View user's profile Send private message
jefflowrey
PostPosted: Fri Jul 16, 2004 2:28 pm    Post subject: Reply with quote

Grand Poobah

Joined: 16 Oct 2002
Posts: 19981

I wouldn't use a listener in this case.

I would use either a standard triggered application or a standard non-triggered application, that simply processess messages on the queue until it gets a 2033 and then quits.
_________________
I am *not* the model of the modern major general.
Back to top
View user's profile Send private message
kiran_tala
PostPosted: Fri Jul 16, 2004 4:04 pm    Post subject: Reply with quote

Novice

Joined: 16 Jul 2004
Posts: 14

Thanks for your response.

Since we are under WAS4.0 (MQ5.3 and MA88 pack) we can't use Message
Driven beans.Thats the reason we had to with the listeners.Since we have
most of the generalized code we took this approach for this processing too.

One more thing is we might have to make this process one day a real time means processing messages real time .Thats the reason we had to goahead and code this as a listener.

right now we have a thread which sits there check the statistics on the
queue and goes to sleep for 10 seconds and this thread keeps the process active until all the messages are processed. We are keeping this thread for 15 minutes.

The problem with this is even though there are no messages it keeps
running. I would like to find out if there is a way to check if there
are no messages and stop this processing(since we can't check the current queue depth with JMS and we can't use direct MQ calls).

This is the way it works now.

My listener implements the Message listener.
It opens up to 10 threads and if there are 10 messages. and once a thread is available in my server session pool it picks the another message
if there is one.I am using receive() method to receive the messages.

I am thinking of trying this with receivenowait() method and take this
extra thread process to keep the process active out and do you think it will
fix the problem.

Please let me know.
Back to top
View user's profile Send private message
jefflowrey
PostPosted: Fri Jul 16, 2004 6:07 pm    Post subject: Reply with quote

Grand Poobah

Joined: 16 Oct 2002
Posts: 19981

kiran_tala wrote:
This application is a standalone JAVA application running under UNIX and this is not running under WAS.


kiran_tala wrote:
Since we are under WAS4.0 (MQ5.3 and MA88 pack) we can't use Message
Which is it?

Are you running your application under WAS or not?

If you want a listener program to stop when there are no more messages, then you need to determine when there are no more messages. That usually means you want the wait to timeout. Then you can tell your code "Hey, look! The listener timed out trying to get messages, and didn't get any messages".

That usually means that there aren't any more messages.

So then you can code your application to shut down.
_________________
I am *not* the model of the modern major general.
Back to top
View user's profile Send private message
kiran_tala
PostPosted: Fri Jul 16, 2004 8:06 pm    Post subject: Reply with quote

Novice

Joined: 16 Jul 2004
Posts: 14

I am sorry. Since we have WAS4.0 and we can't use the message driven
with this WAS version we had to make this application as a standalone one.

Sorry about that.

But anyway how do I check the timeout on wait() method.Can you
explain this more . Thanks,

kiran
Back to top
View user's profile Send private message
jefflowrey
PostPosted: Sat Jul 17, 2004 5:44 am    Post subject: Reply with quote

Grand Poobah

Joined: 16 Oct 2002
Posts: 19981

Looking at the sample ASF classes, what it seems you want to do is have your MessageListener set a flag every time it gets a message.

Your main class should loop while this flag is true, reset the flag to false and sleep for a fixed period of time. When the flag is false after sleep, it means that your MessageListener did not get a message, and then your application can close your sessions and session pools and exit.

Again, this is just based on the samples.

Also, if you are using receive instead of a real MessageListener that gives an onMessage method, then you merely need to use receive(timeout) and check if the returned message is Null. If the returned message is null, then there wasn't a message available within the timeout.

Using Java wrote:
receive
public Message receive(long timeOut) throws JMSException


Receive the next message that arrives within the specified timeout interval. A timeout value of zero causes the call to wait indefinitely until a message arrives.


Parameters:
timeout: the timeout value (in milliseconds).

Returns:
The next message produced for this message consumer, or null if one is not available.

Throws:
JMSException if JMS fails to receive the next message because of an error.

my emphasis.
_________________
I am *not* the model of the modern major general.
Back to top
View user's profile Send private message
kiran_tala
PostPosted: Sat Jul 17, 2004 6:46 am    Post subject: Reply with quote

Novice

Joined: 16 Jul 2004
Posts: 14

All my listeners use Message Listener and I have onMessage() method.

you are right. I am using receive() method.I would check on receive(timeout) method. Anyway where did you find these sample ASF classes.

Thanks for your help.
Back to top
View user's profile Send private message
kiran_tala
PostPosted: Sat Jul 17, 2004 9:35 am    Post subject: Reply with quote

Novice

Joined: 16 Jul 2004
Posts: 14

Hello jefflowrey,

I found the sample code for the ASF classes and appreciate your help
on this.Really this is a great forum.
Back to top
View user's profile Send private message
fjb_saper
PostPosted: Sat Jul 17, 2004 10:31 am    Post subject: Reply with quote

Grand High Poobah

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

Using JMS:

Do not use Message Listener. This would be for exclusive usage like an MDB and it will be alive as long as the program is alive.

We do something like your design is looking for:
Triggered queue at first
process queue until empty using a QueueReceiver and a 10 sec. wait.
exit application.
You will need to do something as to the scalability angle(max threads as a static variable), each thread running its own factory/connection/session instances.

Due to the triggered process the queue is serviced immediately

Be carefull for your trigger monitor. The process starting the trigger monitor in Unix needs a few environment variables set.
Like JAVA_COMPILER=NONE
And the xxxSIGCHILDxxx=YES

Check out the trigger threads using the search button and the documentation.

This comes closest to the behavior of a message driven bean for a stand alone application.

If this were to live in WAS (and you could) I would use a MessageListener to put on the queue but make sure that your process does the following in its shutdown/finalize method:

    Stop the QConnection (do not close it)
    Set the MessageListener to null and attach it to the Queue.
    close the receiver(used to set the MessageListener)
    close the session (remember transactional behavior for JMS)
    close the QConnection


Thus you will release the resources. The behavior will be similar to that of an MDB and you can run it from inside WAS.

Like before in the stand alone application you will need to be able to handle scalability by yourself.

Hope it helps clarify some of the problems
F.J.
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic  Reply to topic Page 1 of 1

MQSeries.net Forum Index » IBM MQ Java / JMS » MQSERIES/JMS/JAVA listeners and not running under WAS
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.