activemq-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Torbjorn Kristoffersen <torbjo...@gmail.com>
Subject Re: How to get the consumer or producer's ip address?
Date Thu, 19 Aug 2010 19:30:45 GMT
On Thu, Aug 19, 2010 at 9:04 PM, Bruce Snyder <bruce.snyder@gmail.com> wrote:
> On Thu, Aug 19, 2010 at 12:42 AM, oliver2010 <zzl_119@sina.com> 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
>> {
>>    class Program
>>    {
>>        static void Main(string[] args)
>>        {
>>            try
>>            {
>>                //Create the Connection factory
>>                IConnectionFactory factory = new
>> ConnectionFactory("tcp://192.168.7.51:61616/");
>>
>>
>>                //Create the connection
>>                using (IConnection connection = factory.CreateConnection())
>>                {
>>                    connection.ClientId = "monitor";
>>                    connection.Start();
>>
>>                    //Create the Session
>>                    using (ISession session = connection.CreateSession())
>>                    {
>>                        IDestination destination =
>> session.GetDestination("ActiveMQ.Advisory.Connection",DestinationType.Topic);
>>                        //Create the Consumer
>>                        IMessageConsumer consumer =
>> session.CreateConsumer(destination);
>>
>>                        consumer.Listener += new
>> MessageListener(consumer_Listener);
>>
>>                        Console.ReadLine();
>>                    }
>>                    connection.Stop();
>>                    connection.Close();
>>                }
>>            }
>>            catch (System.Exception e)
>>            {
>>                Console.WriteLine(e.Message);
>>            }
>>        }
>>
>>        static void consumer_Listener(IMessage message)
>>        {
>>            ActiveMQMessage msg = (ActiveMQMessage)message;
>>            Console.WriteLine(DateTime.Now.ToString() + " : " +
>> msg.ToString());
>>        }
>>    }
>> }
>>
>> Result:
>>
>> 2010/8/19 11:00:06 : ActiveMQMessage[ commandId = 0, responseRe
>> roducerId = ID:DEV-01-3900-1282113492312-1:0:0:0, Destination =
>> .Advisory.Connection, TransactionId = , OriginalDestination = ,
>> EV-01-3900-1282113492312-1:0:0:0:23:34, OriginalTransactionId =
>> oupSequence = 0, CorrelationId = , Persistent = False, Expirati
>> = 0, ReplyTo = , Timestamp = 0, Type = Advisory, Content = , Ma
>> s = System.Byte[], DataStructure = ConnectionInfo[ commandId =
>> ed = True, ConnectionId = ID:X-PC-1489-634178124065831258-1:0,
>> r, Password = , UserName = , BrokerPath = , BrokerMasterConnect
>> eable = False, ClientMaster = False ], TargetConsumerId = ID:X-
>> 065831258-1:0:1:1, Compressed = False, RedeliveryCounter = 0, B
>> ival = 0, UserID = , RecievedByDFBridge = False, Droppable = Fa
>> BrokerInTime = 1282186812265, BrokerOutTime = 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.

Mime
View raw message