Return-Path: Delivered-To: apmail-activemq-users-archive@www.apache.org Received: (qmail 71789 invoked from network); 19 Aug 2010 19:31:13 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 19 Aug 2010 19:31:13 -0000 Received: (qmail 48486 invoked by uid 500); 19 Aug 2010 19:31:13 -0000 Delivered-To: apmail-activemq-users-archive@activemq.apache.org Received: (qmail 48407 invoked by uid 500); 19 Aug 2010 19:31:12 -0000 Mailing-List: contact users-help@activemq.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: users@activemq.apache.org Delivered-To: mailing list users@activemq.apache.org Received: (qmail 48396 invoked by uid 99); 19 Aug 2010 19:31:12 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 19 Aug 2010 19:31:12 +0000 X-ASF-Spam-Status: No, hits=0.0 required=10.0 tests=FREEMAIL_FROM,SPF_PASS,T_TO_NO_BRKTS_FREEMAIL X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of torbjoern@gmail.com designates 209.85.215.171 as permitted sender) Received: from [209.85.215.171] (HELO mail-ey0-f171.google.com) (209.85.215.171) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 19 Aug 2010 19:31:05 +0000 Received: by eye27 with SMTP id 27so1865775eye.2 for ; Thu, 19 Aug 2010 12:30:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:received:in-reply-to :references:date:message-id:subject:from:to:content-type :content-transfer-encoding; bh=UhrpIn7HAPAkJivY+CLlbQqzVgrGv4Ggx0VOEE9rfx0=; b=oyNc9rwB2wUbjUtv54KsLj1MenBPPclUeNRUihOcn2E78XtNBBAqtaeOAv2hdvjk2r alMT1748CTosUPKKRrbE7US9vyDS4t8hQcQ0u6dryn+3WIs4tVdG1bcePGLBtXLE264h DqZsL8iZJXhiz6WCyv8nt3khzLDRCPKuxi8MA= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:content-transfer-encoding; b=IhnrPtGlZYdRDCdn4UlPK5luWu0g8DQuR6xsk9wY1RVbl0FEbGzA7byUuknFTwUUDg EpNxvzlp7L0BZRAXHr/Aj9RinjDncGFh9ZUHg9Jd8Nkht6ZqK0WJeeZiAchmaGubHkVn wTrFrpbDU9E0ni1DKTjJoJr10zdnouCQhlWw8= MIME-Version: 1.0 Received: by 10.213.44.83 with SMTP id z19mr1064610ebe.93.1282246245389; Thu, 19 Aug 2010 12:30:45 -0700 (PDT) Received: by 10.213.108.132 with HTTP; Thu, 19 Aug 2010 12:30:45 -0700 (PDT) In-Reply-To: References: <29478980.post@talk.nabble.com> Date: Thu, 19 Aug 2010 21:30:45 +0200 Message-ID: Subject: Re: How to get the consumer or producer's ip address? From: Torbjorn Kristoffersen To: users@activemq.apache.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Virus-Checked: Checked by ClamAV on apache.org On Thu, Aug 19, 2010 at 9:04 PM, Bruce Snyder wrot= e: > On Thu, Aug 19, 2010 at 12:42 AM, oliver2010 wrote: >> >> I create a MessageConsumer that listens on the advisory topic. >> >> Code: >> >> using System; >> using System.Collections.Generic; >> using System.Linq; >> using System.Text; >> using Apache.NMS; >> using Apache.NMS.ActiveMQ; >> using Apache.NMS.ActiveMQ.Commands; >> using System.IO; >> using System.Xml.Serialization; >> using System.Runtime.Serialization.Formatters.Binary; >> >> namespace Monitor >> { >> =A0 =A0class Program >> =A0 =A0{ >> =A0 =A0 =A0 =A0static void Main(string[] args) >> =A0 =A0 =A0 =A0{ >> =A0 =A0 =A0 =A0 =A0 =A0try >> =A0 =A0 =A0 =A0 =A0 =A0{ >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0//Create the Connection factory >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0IConnectionFactory factory =3D new >> ConnectionFactory("tcp://192.168.7.51:61616/"); >> >> >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0//Create the connection >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0using (IConnection connection =3D factory= .CreateConnection()) >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0{ >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0connection.ClientId =3D "monitor"= ; >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0connection.Start(); >> >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0//Create the Session >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0using (ISession session =3D conne= ction.CreateSession()) >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0{ >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0IDestination destination = =3D >> session.GetDestination("ActiveMQ.Advisory.Connection",DestinationType.To= pic); >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0//Create the Consumer >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0IMessageConsumer consumer= =3D >> session.CreateConsumer(destination); >> >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0consumer.Listener +=3D ne= w >> MessageListener(consumer_Listener); >> >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0Console.ReadLine(); >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0} >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0connection.Stop(); >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0connection.Close(); >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0} >> =A0 =A0 =A0 =A0 =A0 =A0} >> =A0 =A0 =A0 =A0 =A0 =A0catch (System.Exception e) >> =A0 =A0 =A0 =A0 =A0 =A0{ >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0Console.WriteLine(e.Message); >> =A0 =A0 =A0 =A0 =A0 =A0} >> =A0 =A0 =A0 =A0} >> >> =A0 =A0 =A0 =A0static void consumer_Listener(IMessage message) >> =A0 =A0 =A0 =A0{ >> =A0 =A0 =A0 =A0 =A0 =A0ActiveMQMessage msg =3D (ActiveMQMessage)message; >> =A0 =A0 =A0 =A0 =A0 =A0Console.WriteLine(DateTime.Now.ToString() + " : "= + >> msg.ToString()); >> =A0 =A0 =A0 =A0} >> =A0 =A0} >> } >> >> Result: >> >> 2010/8/19 11:00:06 : ActiveMQMessage[ commandId =3D 0, responseRe >> roducerId =3D ID:DEV-01-3900-1282113492312-1:0:0:0, Destination =3D >> .Advisory.Connection, TransactionId =3D , OriginalDestination =3D , >> EV-01-3900-1282113492312-1:0:0:0:23:34, OriginalTransactionId =3D >> oupSequence =3D 0, CorrelationId =3D , Persistent =3D False, Expirati >> =3D 0, ReplyTo =3D , Timestamp =3D 0, Type =3D Advisory, Content =3D , M= a >> s =3D System.Byte[], DataStructure =3D ConnectionInfo[ commandId =3D >> ed =3D True, ConnectionId =3D ID:X-PC-1489-634178124065831258-1:0, >> r, Password =3D , UserName =3D , BrokerPath =3D , BrokerMasterConnect >> eable =3D False, ClientMaster =3D False ], TargetConsumerId =3D ID:X- >> 065831258-1:0:1:1, Compressed =3D False, RedeliveryCounter =3D 0, B >> ival =3D 0, UserID =3D , RecievedByDFBridge =3D False, Droppable =3D Fa >> BrokerInTime =3D 1282186812265, BrokerOutTime =3D 1282186812265 ] >> >> *********************************************************** >> >> The question is i can't get the consumer't ip address? How to get it? > > There is nothing built in to JMS or ActiveMQ for this because it's not > a concern of the broker or the JMS clients. But you can easily put the > ip address in a header property or the message body. > That might not give you the correct IP, though. It may not even be possible to detect the IP.