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 » JMS Listener app fails sending reply

Post new topic  Reply to topic
 JMS Listener app fails sending reply « View previous topic :: View next topic » 
Author Message
rconn2
PostPosted: Sat Jun 07, 2008 6:25 am    Post subject: JMS Listener app fails sending reply Reply with quote

Voyager

Joined: 09 Aug 2007
Posts: 79
Location: MD, USA

I have a JMS Listener application that gets messages from a queue through the onMessage method and then sends a reply message to a queue specified in the JMSReplyTo property of the received message.

I've stress tested the app by sending it a bunch of messages and everything seems okay. But then, the next day it'll fail sending the replies (and once it fails, it continues to fail sending more replies)... or, I've noticed, if unused for a few hours this'll also occur. However, it'll still handle messages okay in onMessage... it'll just fail with the reply.

Here's a simplified order of object creation and use:

Code:
_connection = ...
_ssession =_connection.createQueueSession( false, Session.AUTO_ACKNOWLEDGE);

calls method mqListen(...) {
  asession =_connection.createQueueSession( false, Session.AUTO_ACKNOWLEDGE);

  queue = asession.createQueue( str_queue );
  queueReceiver = asession.createReceiver(queue);
  queueReceiver.setMessageListener(this);
  _connection.setExceptionListener(this);
}

onMessage() {
   ...
  // this is where it fails
  QueueSender qs = _ssession.createSender(q);
}


It fails when creating a QueueSender from the session created at startup (_ssession) for use in sending replies. My understanding is to not use the same session used by the Listener (called asession here).
Back to top
View user's profile Send private message
rconn2
PostPosted: Sat Jun 07, 2008 6:33 am    Post subject: Reply with quote

Voyager

Joined: 09 Aug 2007
Posts: 79
Location: MD, USA

QueueSession _ssession does successfully create the reply text message, and the reply queue... but the error occurs when creating a QueueSender from the session. It's as if the session has gone stale?

I have the exception and linked exception, but it's at work... I'll go in and post the errors on this thread.

Any help would be much appreciated -- this code is being deployed and I need to fix immediately. Do sessions time-out? Should I create a new session just for sending a single reply message (and close after sending)? It's my understanding to not use the same session as the Listener... is this correct? Is using the same connection used by the Listener to create the session used for the reply okay or should connection and session both be seperate?
Back to top
View user's profile Send private message
rconn2
PostPosted: Sat Jun 07, 2008 3:45 pm    Post subject: Reply with quote

Voyager

Joined: 09 Aug 2007
Posts: 79
Location: MD, USA

Here's the error I receive when trying to send a reply message after getting a message in onMessage (mqPutMessage and onMessageProc are just my methods called from onMessage):

Code:
mqReceiveFile: sending reply message...
mqPutMessage: creating QueueSender
onMessageProc: javax.jms.JMSException: MQJMS2008: failed to open MQ queue CMMP.MDCFPSR15_REPLY
onMessageProc: com.ibm.mq.MQException: MQJE001: Completion Code 2, Reason 2009
javax.jms.JMSException: MQJMS2008: failed to open MQ queue CMMP.MDCFPSR15_REPLY
   at com.ibm.mq.jms.MQQueueServices.getQueueOpenException(MQQueueServices.java(Compiled Code))
   at com.ibm.mq.jms.MQQueueServices.getOutputQueue(MQQueueServices.java(Compiled Code))
   at com.ibm.mq.jms.JMSServicesMgr.getOutputQueue(JMSServicesMgr.java(Compiled Code))
   at com.ibm.mq.jms.MQSession.createQSender(MQSession.java(Compiled Code))
   at com.ibm.mq.jms.MQQueueSession.createSender(MQQueueSession.java(Inlined Compiled Code))
   at JMSFile2.mqPutMessage(JMSFile2.java(Compiled Code))
   at JMSFile2.mqReceiveFile(JMSFile2.java(Compiled Code))
   at JMSFile2.onMessageProc(JMSFile2.java(Compiled Code))
   at JMSFile2.onMessage(JMSFile2.java(Compiled Code))
   at com.ibm.mq.jms.MQMessageConsumer.receiveAsync(MQMessageConsumer.java(Compiled Code))
   at com.ibm.mq.jms.contact admin.run(contact admin.java(Compiled Code))
   at java.lang.Thread.run(Thread.java:570)
Back to top
View user's profile Send private message
fjb_saper
PostPosted: Sat Jun 07, 2008 7:05 pm    Post subject: Reply with quote

Grand High Poobah

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

Ok so here is the deal:
When processing a msg in the onMessage method you are blocking that thread. So why not use the current session to create the sender/producer and use that for the reply.

The only reason not to do so would be if the reply needs to be sent via a unit of work (transaction) or a different QC and as such I did not see you use a different QC or QCF or transaction...

Transactionality is handled by session so yes it would be cleaner if you used the same session for the reply. At the same time constantly creating and closing senders/producers creates quite some overhead that can and should be avoided. Use the anonymous sender/provider pattern: see MessageSender.send(Destination, Message);

Just create the sender with a null destination:
Code:
 session.createSender(null);


And yes sessions and connections may go stale or out of scope...
May I suggest that you add an ExceptionListener to the connection?

Enjoy
_________________
MQ & Broker admin
Back to top
View user's profile Send private message Send e-mail
rconn2
PostPosted: Sun Jun 08, 2008 7:37 am    Post subject: Reply with quote

Voyager

Joined: 09 Aug 2007
Posts: 79
Location: MD, USA

Thanks for the reply!

Quote:
So why not use the current session to create the sender/producer and use that for the reply.

I think you mean the listener's session (named asession in my code snip)? I can't find the reference, but in my notes I have it written to not use a listener's session for other sending/receiving. You're saying that using the listener's session, though, is okay as long as there are no transactions and the QC is the same? That'd make things easier for me -- to only use the same session for the listener and sending replies in onMessage.

Thanks for the tip on session.createSender(null);

My code snip shows an ExceptionListener... but it doesn't get called when the session for reply messages fails.

In sum, just to be certain I understand...

Let's say I create 2 member variables for my Listener application class, _assession for async listener session and _ssession for sync session:

Code:
_asession =_connection.createQueueSession( false, Session.AUTO_ACKNOWLEDGE);
_ssession =_connection.createQueueSession( false, Session.AUTO_ACKNOWLEDGE);

I had been using _ssession to send replies in onMessage, but after some time (hours or a day of inactivity), it couldn't create a QueueSender object.

You're saying I should just use _assession for creating a QueueSender object used to send replies in onMessage. Why? Because the Listener's session is going to remain alive, and if no transactions are being used, then using that session for sending replies is okay.

The alternative to using the same Listener's session for both the Listener and sending replies, would be to use a separate session (_ssessioon in the code snip). But, this session has been going stale. So, I'd have to recreate it (close and null it, and re-create) on each onMessage -- which would of course be more resource intensive.

I'm trying to get a firm understanding of the gotcha's on when to use a Listener's session for sending replies, and when to use a separate session. And, how to avoid session's going stale.
Back to top
View user's profile Send private message
rconn2
PostPosted: Mon Jun 09, 2008 10:12 am    Post subject: Reply with quote

Voyager

Joined: 09 Aug 2007
Posts: 79
Location: MD, USA

I found this (any comments?):

http://docs.sun.com/app/docs/doc/819-7757/aeqda?a=view

JMS Threading Restrictions

The Java Messaging Specification mandates that a session not be operated on by more than one thread at a time. This leads to the following restrictions:

A session may not have an asynchronous consumer and a synchronous consumer.

A session that has an asynchronous consumer can only produce messages from within the onMessage() method (the message listener). The only call that you can make outside the message listener is to close the session.

A session may include any number of synchronous consumers, any number of producers, and any combination of the two. That is, the single-thread requirement cannot be violated by these combinations. However, performance may suffer.

The system does not enforce the requirement that a session be single threaded. If your client application violates this requirement, you will get a JMSIllegalState exception or unexpected results.
Back to top
View user's profile Send private message
fjb_saper
PostPosted: Mon Jun 09, 2008 1:41 pm    Post subject: Reply with quote

Grand High Poobah

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

I think you took my comment about transaction the wrong way.

What I was saying is that if you do use transactionality you HAVE to use the same session as the session defines the transaction's borders with the session.commit and session.rollback methods.

Also using a different session can become cumbersome quite quickly as you need to
a) create the session
b) create the producer
c) send the message
d) close the producer
f) close the session

and you still gain little to no advantage if you don't do it on its own connection.

Now opening and closing connections is a very costly (resource intensive) thing...

So yes stick with it and use the same session as in the MDB.

Enjoy
_________________
MQ & Broker admin
Back to top
View user's profile Send private message Send e-mail
rconn2
PostPosted: Mon Jun 09, 2008 3:35 pm    Post subject: Reply with quote

Voyager

Joined: 09 Aug 2007
Posts: 79
Location: MD, USA

Thanks fjb. I've coded to use the Listener's session when sending a reply upon onMessage getting called. ... seems to be working well.
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 » JMS Listener app fails sending reply
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.