On Thu, Aug 19, 2010 at 12:42 AM, oliver2010 <zzl_...@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.

Bruce
-- 
perl -e 'print 
unpack("u30","D0G)u8...@4vyy9&5R\"F)R=6-E+G-N>61E<D\!G;6%I;\"YC;VT*"
);'

ActiveMQ in Action: http://bit.ly/2je6cQ
Blog: http://bruceblog.org/
Twitter: http://twitter.com/brucesnyder

Reply via email to