Author |
Message
|
hyperspike |
Posted: Fri Jun 25, 2010 6:00 am Post subject: Configuring a message listener as MQGET |
|
|
Novice
Joined: 24 May 2010 Posts: 18
|
I have a stand alone java program that i am using to connect to an MQ server. I create a connection using the connection factory then create a session, then a destination and then a consumer. I set a message listener on the consumer and i am seeing messages come through, however they are not being pulled off of the queue.
I did some research and it appears that the client is just browsing the messages and not getting them.
How/where do i configure this guy to get the messages off of the queue so once they are read the are gone??
thanks |
|
Back to top |
|
 |
fjb_saper |
Posted: Fri Jun 25, 2010 10:17 am Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
So you have built the connection, session, consumer and passed the listener to the consumer. Did you explicitely start the connection? Are you committing the session? Are you throwing any execptions that are not caught in the onMessage method?  _________________ MQ & Broker admin |
|
Back to top |
|
 |
hyperspike |
Posted: Fri Jun 25, 2010 10:18 am Post subject: |
|
|
Novice
Joined: 24 May 2010 Posts: 18
|
No i can start the connection and get the messages in the listener, but they don't come off of the queue, so i am assuming that i am just browsing the messages and not getting them... |
|
Back to top |
|
 |
hyperspike |
Posted: Fri Jun 25, 2010 10:20 am Post subject: |
|
|
Novice
Joined: 24 May 2010 Posts: 18
|
Its actaully a text message and i can get it and process it, but the message stays on the queue...
So if i connected i get 10 messages...then i disconnect, then reconnect and i get the same 10 messages again... |
|
Back to top |
|
 |
fjb_saper |
Posted: Fri Jun 25, 2010 10:27 am Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
hyperspike wrote: |
Its actaully a text message and i can get it and process it, but the message stays on the queue...
So if i connected i get 10 messages...then i disconnect, then reconnect and i get the same 10 messages again... |
Unless you use the browser class you are not browsing.
How are you creating your session?
Code: |
Session mysess = conn.createSession(true, Session.AUTO_ACKNOWLEDGE); |
And make sure that you explicitely commit the session as this is stand alone JMS.  _________________ MQ & Broker admin |
|
Back to top |
|
 |
hyperspike |
Posted: Fri Jun 25, 2010 10:29 am Post subject: |
|
|
Novice
Joined: 24 May 2010 Posts: 18
|
Code: |
Session ses = con.createSession(true, Session.AUTO_ACKNOWLEDGE);
Destination queue = ses.createQueue("XXXX");
MessageConsumer consumer = ses.createConsumer(queue);
consumer.setMessageListener(new xXXListener());
con.start(); |
|
|
Back to top |
|
 |
fjb_saper |
Posted: Fri Jun 25, 2010 10:35 am Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
hyperspike wrote: |
Code: |
Session ses = con.createSession(true, Session.AUTO_ACKNOWLEDGE);
Destination queue = ses.createQueue("XXXX");
MessageConsumer consumer = ses.createConsumer(queue);
consumer.setMessageListener(new xXXListener());
con.start(); |
|
You need to add something like in the onMessage method at the end...
Code: |
//process message
getSession().commit(); |
It looks like your platform does a rollback if no explicit commit is done.  _________________ MQ & Broker admin |
|
Back to top |
|
 |
hyperspike |
Posted: Fri Jun 25, 2010 10:38 am Post subject: |
|
|
Novice
Joined: 24 May 2010 Posts: 18
|
So i need to pass teh session into the listener and then commit after each read? but the commit has to be on the session correct?
thanks so much for your help!
Ill post the results.... |
|
Back to top |
|
 |
fjb_saper |
Posted: Fri Jun 25, 2010 10:41 am Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
hyperspike wrote: |
So i need to pass teh session into the listener and then commit after each read? but the commit has to be on the session correct?
thanks so much for your help!
Ill post the results.... |
Remember as you are stand alone there is no automatic transaction handling being done (like a requires new for the onMessage method) and the transaction manager does not commit at the end of the Method.
You will have to handle your transaction boundaries manually.  _________________ MQ & Broker admin |
|
Back to top |
|
 |
hyperspike |
Posted: Fri Jun 25, 2010 10:47 am Post subject: |
|
|
Novice
Joined: 24 May 2010 Posts: 18
|
That did it, Thanks so much for your help!
I have done JMS in an OC4J container but never standalone, and that makes a lot more sense now and i see what i was doing wrong.
Thanks again! |
|
Back to top |
|
 |
|