activemq-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jlittman <jlitt...@google.com>
Subject Re: Detecting lost clients
Date Wed, 06 Sep 2006 04:24:34 GMT

Unless I'm reading the activemq source wrong, it looks like I can use
ActiveMQMessage.getProducerId().getConnectionId() when I receive messages
and it matches with connectionInfo.getConnectionId() from below. This works
in my testing, so I think I'm good unless someone tells me I'm relying on
something incorrect, or something that is subject to change.




jlittman wrote:
> 
> The connectionId and clientId seem to be the same. And they don't match
> what I'm getting from my delivered JMS message. Code and output as
> follows:
> 
>             if (activeMQMessage.getDataStructure() instanceof
> ConnectionInfo) {
>                 ConnectionInfo connectionInfo = (ConnectionInfo)
> activeMQMessage.getDataStructure();
>                 logger.info("received connection notice " +
> connectionInfo.getConnectionId());
>                 logger.info("received connection notice clientid"
>                         + connectionInfo.getClientId());
>                 logger.info("received clientid"
>                         + activeMQMessage.getConnection().getClientID());
>                 logger.info("received initialized clientid"
>                         +
> activeMQMessage.getConnection().getInitializedClientID());
>             }
> 
> 2006-09-04 08:42:19,700 INFO  [Thread-28] ConnectionMonitor.info -
> received connection notice ID:server-corp-1768-1157384519543-15:0
> 2006-09-04 08:42:19,700 INFO  [Thread-28] ConnectionMonitor.info -
> received connection notice clientidID:server-corp-1768-1157384519543-15:0
> 2006-09-04 08:42:19,700 INFO  [Thread-28] ConnectionMonitor.info -
> received clientidID:server-corp-1768-1157384519543-14:0
> 2006-09-04 08:42:19,700 INFO  [Thread-28] ConnectionMonitor.info -
> received initialized clientidID:server-corp-1768-1157384519543-14:0
> 
> And on the message receive side:
> 
>         logger.error ("connection id is " +
> activeMQMessage.getConnection().getConnectionInfo().getConnectionId());
>         //ConnectionInfo connectionInfo = (ConnectionInfo)
> activeMQMessage.getDataStructure();
>         //logger.error ("(hopefully)client id is " +
> connectionInfo.getClientId());
> 
>         try {
>             logger.error ("client id is " +
> activeMQMessage.getConnection().getClientID());
>         } catch (JMSException e) {
>             // TODO Auto-generated catch block
>             e.printStackTrace();
>         }
> 
> 
> 2006-09-04 08:42:21,404 ERROR [Thread-29] RequestReplyController.onMessage
> - connection id is ID:server-corp-1768-1157384519543-5:4
> 2006-09-04 08:42:21,404 ERROR [Thread-29] RequestReplyController.onMessage
> - client id is ID:server-corp-1768-1157384519543-10:0
> 
> 
> 
> James.Strachan wrote:
>> 
>> I think the issue is how you are unpacking the advisory. Its a little
>> non-intuitive, but to unpack the details of the advisory (as apposed
>> to looking at the current client's connection) try
>> 
>> command = activemqMessage.getDataStructure();
>> 
>> then cast it to a RemoveInfo for a removal of a
>> connection/producer/consumer and you should be able to extract the
>> actual client ID from that.
>> 
>> e.g. see the onMessage() method on ConsumerEventSource for a hint at
>> how to do it.
>> 
>> We could create a
>> ConnectionEvent/ConnectionListener/ConnectionEventSource in a similar
>> way to the Producer/Consumer helper classes in the advisory package to
>> hide some of the lower level details of the implementation of
>> advisories and openwire).
>> 
>> On 9/4/06, jlittman <jlittman@google.com> wrote:
>>>
>>> Thanks James, but it still doesn't seem to line up. I tried clients from
>>> java
>>> and from stomp, with similar results.
>>> Adding the code to my connection monitor object:
>>>
>>>         try {
>>>                 logger.info("received connection notice clientid"
>>>                         +
>>> activeMQMessage.getConnection().getClientID());
>>>         } catch (JMSException e) {
>>>             // TODO Auto-generated catch block
>>>             e.printStackTrace();
>>>         }
>>>
>>> produces:
>>>
>>> 2006-09-04 07:22:05,328 INFO  [Thread-40] server.ConnectionMonitor.info
>>> -
>>> received connection notice
>>> clientidID:server-corp-1092-1157379254703-10:0
>>>
>>> and adding code to my onMessage handler:
>>>
>>>         try {
>>>             logger.error ("client id is " +
>>> activeMQMessage.getConnection().getClientID());
>>>         } catch (JMSException e) {
>>>             // TODO Auto-generated catch block
>>>             e.printStackTrace();
>>>         }
>>>
>>>
>>> 2006-09-04 07:22:06,578 ERROR [Thread-41]
>>> RequestReplyController.onMessage -
>>> client id is ID:server-corp-1092-1157379254703-13:0
>>>
>>>
>>>
>>> James.Strachan wrote:
>>> >
>>> > Try use the clientID of the JMS Connection.
>>> >
>>> > Connection.getClientId()
>>> >
>>> >
>>> http://java.sun.com/j2ee/1.4/docs/api/javax/jms/Connection.html#getClientID()
>>> >
>>> > to correlate between advisories and a specific JMS connection.
>>> >
>>> > On 9/3/06, jlittman <jlittman@google.com> wrote:
>>> >>
>>> >> It looks like I'm close, maybe someone can suggest the last piece.
>>> >>
>>> >> Following basic instructions found in:
>>> >> http://www.activemq.org/site/advisory-message.html
>>> >>
>>> >> Subscribe to ActiveMQ.Advisory.Connection. Can keep track of
>>> connections
>>> >> coming and going as follows:
>>> >>     public void onMessage(Message msg) {
>>> >>         ActiveMQMessage activeMQMessage = (ActiveMQMessage) msg;
>>> >>         if (activeMQMessage.getDataStructure() instanceof
>>> ConnectionInfo)
>>> >> {
>>> >>             ConnectionInfo connectionInfo = (ConnectionInfo)
>>> >> activeMQMessage.getDataStructure();
>>> >>             logger.info("received connection notice " +
>>> >> connectionInfo.getConnectionId());
>>> >>         } else if (activeMQMessage.getDataStructure() instanceof
>>> >> RemoveInfo)
>>> >> {
>>> >>             RemoveInfo removeInfo = (RemoveInfo)
>>> >> activeMQMessage.getDataStructure();
>>> >>             logger.info("received remove notice " +
>>> >> (ConnectionId)removeInfo.getObjectId());
>>> >>         }
>>> >>     }
>>> >>
>>> >> and when I receive a message, I try to correlate it with my connected
>>> >> client
>>> >> as follows:
>>> >>
>>> >>         ActiveMQMessage activeMQMessage = (ActiveMQMessage)
>>> jmsMessage;
>>> >>         ProducerId producerId = activeMQMessage.getProducerId();
>>> >>         logger.info ("producer id is " + producerId);
>>> >>         logger.info ("connection id is " +
>>> >>
>>> activeMQMessage.getConnection().getConnectionInfo().getConnectionId());
>>> >>
>>> >> The problem is that the output is:
>>> >>
>>> >> 2006-09-03 08:15:56,439 INFO  [Thread-35]
>>> >> com.dmarc.ras.common.server.ConnectionMonitor.info - received
>>> connection
>>> >> notice ID:server-corp-2975-1157296540985-18:0
>>> >> 2006-09-03 08:16:03,611 INFO [Thread-38] controller.onMessage -
>>> producer
>>> >> id
>>> >> is ID:server-corp-2975-1157296540985-18:0:-1:1
>>> >> 2006-09-03 08:16:03,611 INFO [Thread-38] controller.onMessage -
>>> >> connection
>>> >> id is ID:server-corp-2975-1157296540985-6:4
>>> >>
>>> >>
>>> >> So the connectId doesn't match, but the producerId *almost* matches.
>>> So I
>>> >> guess I don't quite have the way to match the connection events with
>>> the
>>> >> incoming messages.
>>> >>
>>> >>
>>> >>
>>> >>
>>> >> jlittman wrote:
>>> >> >
>>> >> > From my ActiveMQ server application, I want to be able to detect
>>> when a
>>> >> > client has disappeared (i.e. crash) without explicitly closing
the
>>> >> > application level session. What I'd like to do is the following:
>>> >> > 1) receive ApplicationConnect message from a client. Save some
sort
>>> of
>>> >> an
>>> >> > id representing the connection.
>>> >> > 2) If the application disconnects or exits ungracefully without
>>> sending
>>> >> an
>>> >> > ApplicationDisconnect message, I want to receive notification that
>>> the
>>> >> > client with the given id is gone, and I should clean up all
>>> relevant
>>> >> > state, locks, etc....
>>> >> >
>>> >> > I can set up a MessageListener interested in topic
>>> >> > ActiveMQ.Advisory.Connection, and I get a message delivered when
>>> >> clients
>>> >> > connect and when they disconnect or crash. When I get a JMS message
>>> for
>>> >> > ApplicationConnect, I can see that there is ConnectionInfo in the
>>> data
>>> >> > structure for Message. However, I don't see any values that
>>> correlate
>>> >> with
>>> >> > the ConnectionInfo received in the ActiveMQ.Advisory.Connection
>>> topic
>>> >> > message. There's a clientId, sessionId etc... but they don't seem
>>> to be
>>> >> > the value I am after. Is there a value here that I can use, or
is
>>> there
>>> >> a
>>> >> > better way to build this mousetrap altogether? Thanks in advance
>>> for
>>> >> any
>>> >> > tips.
>>> >> >
>>> >>
>>> >> --
>>> >> View this message in context:
>>> >> http://www.nabble.com/Detecting-lost-clients-tf2208237.html#a6123603
>>> >> Sent from the ActiveMQ - User forum at Nabble.com.
>>> >>
>>> >>
>>> >
>>> >
>>> > --
>>> >
>>> > James
>>> > -------
>>> > http://radio.weblogs.com/0112098/
>>> >
>>> >
>>>
>>> --
>>> View this message in context:
>>> http://www.nabble.com/Detecting-lost-clients-tf2208237.html#a6136537
>>> Sent from the ActiveMQ - User forum at Nabble.com.
>>>
>>>
>> 
>> 
>> -- 
>> 
>> James
>> -------
>> http://radio.weblogs.com/0112098/
>> 
>> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Detecting-lost-clients-tf2208237.html#a6164707
Sent from the ActiveMQ - User forum at Nabble.com.


Mime
View raw message