tags:

views:

278

answers:

2

I have a "server" application receiving messages from a JMS queue. And client applications which create a temp queue, and then send a message to the server, setting the JMSReplyTo header to the temp queue.

The server replies back to the client using the temp queue. However the server has a lot of replies back to the client all sent over the temp queue for a long period of time.(The replies are specific to that client, and are not interesting to anyone else)

How can my server detect if the client disconnected - so I can stop sending messages over that particular temp queue ? Or am I trying to do things with JMS I shouldn't ?

A: 

Well, posting to that queue should fail since it should no longer exist once the client is gone. The temporary queue is only supposed to exist while the session that created it exists.

So I don't see that there is a need to be notified when the client is gone, which you can't do via JMS, as the attempt to send a reply message will in fact indicate this.

Robin
Well, some initial testing (with activemq) shows the server side just keep sending with no error to the temp queue atlest 20 seconds after the client is terminated
nos
Maybe the unprocessed messages in the queue keep it alive? How about a cooperative solution: client signals the server an end-of-messaging message?
kd304
That would be a suboptimal solution that requires the client to never ever crash and requires the network to always be operative (else that end-of-messaging message might never be sent)
nos
@noselasd - Don't know what to tell you since I have never used them. Some documentation http://www.onjava.com/pub/a/onjava/2007/04/10/designing-messaging-applications-with-temporary-queues.html here as well as other places claim that lifespan is terminated with the connection or session that created it and contents of queue are lost. I would assume that sending new messages should then fail, apparently that is incorrect, or the implementation is flawed.
Robin
Seems to be a problem with the .NET libraries of activeMQ. Using Java and the JMS libraries I do get an exception when trying to send to a temp queue where the client is gone :-
nos
I am glad to hear that it works as expected. You didn't actually mention anything about .NET in the question, that is a whole other beast.
Robin
A: 

With activeMQ, you can cast your temporary queue to a Destination and then interrogate the destination, e.g. if (dest.getConsumers().size() < 1) { // No more consumers on this destination, so kill it. }

Or from the destination, get the DestinationStatistics, and then get the queue depth from getMessages(), if greater than "n" then kill the tempQ.

crowne