Author |
Message
|
subhendu |
Posted: Mon Mar 11, 2002 12:58 pm Post subject: |
|
|
Novice
Joined: 05 Mar 2002 Posts: 18
|
Hi i want to implement a Messagelistener Using MQ Pure JAva. I know Using JMS it can be done. But i want to use MQ java due to some restriction.
That means as soon as message arrives in the queue my program should run.
Any ideacode samples how to implement this.
Thanks,
Subhendu |
|
Back to top |
|
 |
bduncan |
Posted: Mon Mar 11, 2002 1:15 pm Post subject: |
|
|
Padawan
Joined: 11 Apr 2001 Posts: 1554 Location: Silicon Valley
|
|
Back to top |
|
 |
subhendu |
Posted: Mon Mar 11, 2002 4:44 pm Post subject: |
|
|
Novice
Joined: 05 Mar 2002 Posts: 18
|
my concern is using JMS i can define a MessageListener so that when a message arrives it will trigger the onmessage method of listener.
So is there such type of implementation in MQ base java classes?
THanks,
Subhendu |
|
Back to top |
|
 |
kolban |
Posted: Mon Mar 11, 2002 5:54 pm Post subject: |
|
|
 Grand Master
Joined: 22 May 2001 Posts: 1072 Location: Fort Worth, TX, USA
|
No .. but think what is going on here. By registering a message listener, you are asking for messages to be handled asynchronoulsy from your initial thread. You can trivially (and in my opinion with much more power) achieve the same task using base java MQ classes.
Simply create a new thread which creates a new MQQueueManager object, accesses a queue and then performs a get() method call blocking on a message arriving. |
|
Back to top |
|
 |
subhendu |
Posted: Tue Mar 12, 2002 6:28 am Post subject: |
|
|
Novice
Joined: 05 Mar 2002 Posts: 18
|
The message comes to queue asynchronously. That means message comes to the queue when user from online system submits some thing.So it is totally asynchronous.In this case if i have a jms listener then i need not to worry. I will register it to the queue and i will call the start method in side a startup servlet. so at any time message comes it will pick up.
But if i am using the base MQ class it will pick up message once and process it and thread will go down. So how to achieve the same functionality menioned above by jms.
Thanks,
Subhendu |
|
Back to top |
|
 |
kolban |
Posted: Tue Mar 12, 2002 7:21 am Post subject: |
|
|
 Grand Master
Joined: 22 May 2001 Posts: 1072 Location: Fort Worth, TX, USA
|
You own the thread using base java ... why not put it in a loop. ... Get the message, process the message, get the message, process the message ....
The thread doesn't have to end just because you got a message. If you want multiple messages to be processed concurrently, spawn a new thread yourself and pass in the MQMessage as a parameter. |
|
Back to top |
|
 |
subhendu |
Posted: Tue Mar 12, 2002 7:43 am Post subject: |
|
|
Novice
Joined: 05 Mar 2002 Posts: 18
|
The message does not come always. Message comes and then may be for some time there will be no message.Making loop ,will it not be performance problem?
FOr example some application will put a message and after one or two hour another messsage arrives. So in that case the loop will be always regardless there is message in the queue or not. |
|
Back to top |
|
 |
kolban |
Posted: Tue Mar 12, 2002 10:07 am Post subject: |
|
|
 Grand Master
Joined: 22 May 2001 Posts: 1072 Location: Fort Worth, TX, USA
|
The loop will contain an MQGET call with a wait interval, potentially infinite. While the MQGET call is blocked waiting for a message, it consumes no CPU. |
|
Back to top |
|
 |
|