You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@activemq.apache.org by jlittman <jl...@google.com> on 2006/09/02 22:22:33 UTC
Detecting lost clients
>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#a6116203
Sent from the ActiveMQ - User forum at Nabble.com.
Re: Detecting lost clients
Posted by jlittman <jl...@google.com>.
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 <jl...@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 <jl...@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.
Re: Detecting lost clients
Posted by jlittman <jl...@google.com>.
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 <jl...@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 <jl...@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#a6137775
Sent from the ActiveMQ - User forum at Nabble.com.
Re: Detecting lost clients
Posted by James Strachan <ja...@gmail.com>.
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 <jl...@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 <jl...@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/
Re: Detecting lost clients
Posted by jlittman <jl...@google.com>.
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 <jl...@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.
Re: Detecting lost clients
Posted by James Strachan <ja...@gmail.com>.
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 <jl...@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/
Re: Detecting lost clients
Posted by jlittman <jl...@google.com>.
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.
Re: Detecting lost clients
Posted by masterov <al...@us.icap.com>.
James.Strachan wrote:
>
> This sounds a bit odd; I'm not sure why its behaving like that. The
> maxInactivityDuration should be detecting inactivity on a connection
> and closing it.
>
> http://incubator.apache.org/activemq/configuring-wire-formats.html
>
> I wonder if setting it to a small value helps?
>
I should've mentioned that my client uses activemq-cpp library, which uses
the stomp protocol, and it doesn't seem to accept those options. Do you
know if there are similar options for the stomp protocol?
--
View this message in context: http://www.nabble.com/Detecting-lost-clients-tf2208237.html#a8394152
Sent from the ActiveMQ - User mailing list archive at Nabble.com.
Re: Detecting lost clients
Posted by James Strachan <ja...@gmail.com>.
This sounds a bit odd; I'm not sure why its behaving like that. The
maxInactivityDuration should be detecting inactivity on a connection
and closing it.
http://incubator.apache.org/activemq/configuring-wire-formats.html
I wonder if setting it to a small value helps?
On 1/16/07, masterov <al...@us.icap.com> wrote:
>
> Hey James,
>
> James.Strachan wrote:
> >
> > Just out of interest; are you sure the broker detected the loss of the
> > client? Depending on your OS and the settings, it might be its taking
> > the broker a while to detect client loss. e.g. 30 seconds from
> > pressing CTRL-C.
> >
> > So I wonder, if you look in JConsole, is the client connection gone
> > but you didn't receive an advisory?
> >
> That indeed is the problem: "the broker does not detect a client loss", and
> it's not a matter of 30 seconds, the number of consumers stays the same
> until the next message is sent to that topic, and only after that I get
> "RemoveInfo" and the number of consumers is decremented.
>
> Thanks to your response I realized that this is happening.
>
> So perhaps that is ok, and I should really work with this behaviour. For
> example if there was no message on a topic for a certain period of time -
> fire an empty message just to ensure that all "RemoveInfo" notifications are
> sent. Or is there an easier way?
>
> --
> View this message in context: http://www.nabble.com/Detecting-lost-clients-tf2208237.html#a8393093
> Sent from the ActiveMQ - User mailing list archive at Nabble.com.
>
>
--
James
-------
http://radio.weblogs.com/0112098/
Re: Detecting lost clients
Posted by masterov <al...@us.icap.com>.
James,
James.Strachan wrote:
>
> FWIW this is now fixed in trunk and the next 4.2-snapshot build
>
I checked out the latest trunk, and this behavior didn't change. When the
client disconnects "RemoveInfo" message isn't sent until I send any other
message to the topic in question.
instead I started getting linker warnings like this one:
"ld: warning: symbol `typeinfo for cms::CMSException' has differing sizes:
(file admClient.o value=0x8; file
~/lib/libactivemq-cpp.a(ActiveMQConnectionFactory.o) value=0xc);
admClient.o definition taken"
Thanks,
AM
--
View this message in context: http://www.nabble.com/Detecting-lost-clients-tf2208237.html#a8539685
Sent from the ActiveMQ - User mailing list archive at Nabble.com.
Re: Detecting lost clients
Posted by James Strachan <ja...@gmail.com>.
On 1/16/07, masterov <al...@us.icap.com> wrote:
> Hey James,
> James.Strachan wrote:
> > Just out of interest; are you sure the broker detected the loss of the
> > client? Depending on your OS and the settings, it might be its taking
> > the broker a while to detect client loss. e.g. 30 seconds from
> > pressing CTRL-C.
> >
> > So I wonder, if you look in JConsole, is the client connection gone
> > but you didn't receive an advisory?
> >
> That indeed is the problem: "the broker does not detect a client loss", and
> it's not a matter of 30 seconds, the number of consumers stays the same
> until the next message is sent to that topic, and only after that I get
> "RemoveInfo" and the number of consumers is decremented.
FWIW this is now fixed in trunk and the next 4.2-snapshot build
--
James
-------
http://radio.weblogs.com/0112098/
Re: Detecting lost clients
Posted by masterov <al...@us.icap.com>.
Hey James,
James.Strachan wrote:
>
> Just out of interest; are you sure the broker detected the loss of the
> client? Depending on your OS and the settings, it might be its taking
> the broker a while to detect client loss. e.g. 30 seconds from
> pressing CTRL-C.
>
> So I wonder, if you look in JConsole, is the client connection gone
> but you didn't receive an advisory?
>
That indeed is the problem: "the broker does not detect a client loss", and
it's not a matter of 30 seconds, the number of consumers stays the same
until the next message is sent to that topic, and only after that I get
"RemoveInfo" and the number of consumers is decremented.
Thanks to your response I realized that this is happening.
So perhaps that is ok, and I should really work with this behaviour. For
example if there was no message on a topic for a certain period of time -
fire an empty message just to ensure that all "RemoveInfo" notifications are
sent. Or is there an easier way?
--
View this message in context: http://www.nabble.com/Detecting-lost-clients-tf2208237.html#a8393093
Sent from the ActiveMQ - User mailing list archive at Nabble.com.
Re: Detecting lost clients
Posted by James Strachan <ja...@gmail.com>.
On 1/16/07, masterov <al...@us.icap.com> wrote:
> Hi,
> jlittman wrote:
> >
> > 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.
> >
>
> I am trying to do exactly the same thing, but I don't get any notification
> on ActiveMQ.Advisory.Connection when the client exits ungracefully (i.e.
> CTRL-C or Crashes). Did you need to change any configuration in order to
> start receiving those messages?
Just out of interest; are you sure the broker detected the loss of the
client? Depending on your OS and the settings, it might be its taking
the broker a while to detect client loss. e.g. 30 seconds from
pressing CTRL-C.
So I wonder, if you look in JConsole, is the client connection gone
but you didn't receive an advisory?
--
James
-------
http://radio.weblogs.com/0112098/
Re: Detecting lost clients
Posted by masterov <al...@us.icap.com>.
Hi,
jlittman wrote:
>
> 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.
>
I am trying to do exactly the same thing, but I don't get any notification
on ActiveMQ.Advisory.Connection when the client exits ungracefully (i.e.
CTRL-C or Crashes). Did you need to change any configuration in order to
start receiving those messages?
--
View this message in context: http://www.nabble.com/Detecting-lost-clients-tf2208237.html#a8392657
Sent from the ActiveMQ - User mailing list archive at Nabble.com.
RE: Detecting lost clients
Posted by masterov <al...@us.icap.com>.
tabish121 wrote:
>
> Sounds like you need to do a clean on your App and the CMS library and
> rebuild.
>
This is no longer an issue, the problem was in an inconsistent path to the
headers.
However the problem described earlier (Broker does _not_ detect client
disconnect until the next message is sent to the topic in question) still
exists. My clients are CPP using activemq-cpp (stomp). any ideas?
--
View this message in context: http://www.nabble.com/Detecting-lost-clients-tf2208237.html#a8568172
Sent from the ActiveMQ - User mailing list archive at Nabble.com.