Return-Path: Delivered-To: apmail-geronimo-activemq-users-archive@www.apache.org Received: (qmail 90568 invoked from network); 4 Sep 2006 14:55:12 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 4 Sep 2006 14:55:12 -0000 Received: (qmail 82262 invoked by uid 500); 4 Sep 2006 14:55:12 -0000 Delivered-To: apmail-geronimo-activemq-users-archive@geronimo.apache.org Received: (qmail 82077 invoked by uid 500); 4 Sep 2006 14:55:11 -0000 Mailing-List: contact activemq-users-help@geronimo.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: activemq-users@geronimo.apache.org Delivered-To: mailing list activemq-users@geronimo.apache.org Received: (qmail 82068 invoked by uid 99); 4 Sep 2006 14:55:11 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 04 Sep 2006 07:55:11 -0700 X-ASF-Spam-Status: No, hits=1.3 required=10.0 tests=DNS_FROM_RFC_ABUSE,INFO_TLD,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (asf.osuosl.org: domain of james.strachan@gmail.com designates 64.233.184.232 as permitted sender) Received: from [64.233.184.232] (HELO wr-out-0506.google.com) (64.233.184.232) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 04 Sep 2006 07:55:10 -0700 Received: by wr-out-0506.google.com with SMTP id i5so478503wra for ; Mon, 04 Sep 2006 07:54:50 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=VJqJvSdiqjQSh3KG+SrrE/z/JEVxB3kKLXa/d6Lihxhe7rFEDRZlLFw9ICDKEGqJggXOvLTPqtUK213uVLNd5O6u6ZXMl5/7YsIw+aEKuvzyyKrQngeDQ8cSc7atd9PC9Ajevkjo74x52B57AlRMCA+k1Rl/pIvgliJ1oAeNLqw= Received: by 10.90.113.20 with SMTP id l20mr1127482agc; Mon, 04 Sep 2006 07:54:49 -0700 (PDT) Received: by 10.90.86.4 with HTTP; Mon, 4 Sep 2006 07:54:49 -0700 (PDT) Message-ID: Date: Mon, 4 Sep 2006 15:54:49 +0100 From: "James Strachan" To: activemq-users@geronimo.apache.org Subject: Re: Detecting lost clients In-Reply-To: <6136537.post@talk.nabble.com> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <6116203.post@talk.nabble.com> <6123603.post@talk.nabble.com> <6136537.post@talk.nabble.com> X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N 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 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 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/