Author |
Message
|
manojsingh |
Posted: Tue Jun 07, 2005 12:53 pm Post subject: MQ Listener help.... |
|
|
Newbie
Joined: 07 Jun 2005 Posts: 3
|
Hi,
I am little new to the MQ world. I have been working with MDB etc so far so I know how to create MessageListeners in a App server environment. But now I need to create a stand alone java program which will act as a Listener to a MQ queue. I can write the code but I don't know how to make it running all the time and get messages as they are recd. on the relevant queue. ...can someone please point me in the right direction.
Thanks in advance.
MS |
|
Back to top |
|
 |
fjb_saper |
Posted: Tue Jun 07, 2005 1:02 pm Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
Use JMS, use the listener pattern, and set the MessageListener on the receiver.
To receive messages start the connection.
To stop receiving messages stop the connection
When done:
Stop the connection
set the listener on the receiver to null
close the receiver
close the session
close the connection
And remember setting session attributes for transaction boundaries and committing the session ( in the onMessage() method)....
Enjoy  |
|
Back to top |
|
 |
bower5932 |
Posted: Tue Jun 07, 2005 1:15 pm Post subject: |
|
|
 Jedi Knight
Joined: 27 Aug 2001 Posts: 3023 Location: Dallas, TX, USA
|
|
Back to top |
|
 |
manojsingh |
Posted: Wed Jun 08, 2005 6:13 am Post subject: Thanks |
|
|
Newbie
Joined: 07 Jun 2005 Posts: 3
|
Hi,
Thanks for the replies....just to make sure I am understanding what you mentioned fjb_saper .... I need to create my own listener class ...and since mq.receive(..) (signature or method name might be wrong) is a blocking call the process will wait till the time a message is recd in the reciever queue.. . ...once the execution reaches the next line in my code I will know that the message is recd and I can process the message ....I need to put this in kind of infinite loop ...or till I explicitly close the connection...please correct me if I am wrong..
Thanks again to all of you for your help.
Manoj |
|
Back to top |
|
 |
bower5932 |
Posted: Wed Jun 08, 2005 6:33 am Post subject: |
|
|
 Jedi Knight
Joined: 27 Aug 2001 Posts: 3023 Location: Dallas, TX, USA
|
If you are using the WMQ java api (ie, not JMS), then the MQQueue.get() method will block until a message is received. This is assuming that you are specifying that you want to wait for a message (MQC.MQGMO_WAIT) and that you give an infinite timeout (MQC.MQWI_UNLIMITED). If you are going to block like this, then you should also specify that your get should end if the qmgr is shutting down (MQC.MQGMO_FAIL_IF_QUIESCING).
Your earlier appends lead me to believe that you may be using JMS. If that is the case, you can setup an asynchronous message listener to listen for incoming messages (take a look at the mqjmssub.java program at the URL above). You could also skip the asynchronous message listener and have your program listen synchronously (ie, block, take a look at mqjmssrv.java). |
|
Back to top |
|
 |
manojsingh |
Posted: Wed Jun 08, 2005 10:18 am Post subject: Thanks |
|
|
Newbie
Joined: 07 Jun 2005 Posts: 3
|
bower5932 ....I think I am in a good now....thanks for your help I really appreciate it.. if there is any problem then....I will post it here again...
Thanks
Manoj |
|
Back to top |
|
 |
|