You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@activemq.apache.org by oliver2010 <zz...@sina.com> on 2010/08/19 08:42:37 UTC

How to get the consumer or producer's ip address?

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?

-- 
View this message in context: http://old.nabble.com/How-to-get-the-consumer-or-producer%27s-ip-address--tp29478980p29478980.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.


Re: How to get the consumer or producer's ip address?

Posted by oliver2010 <zz...@sina.com>.
The following code is in connections.jsp , it can get the RemoteAddress



--------------------------------------------------------------------------
<h2>Connection ${requestContext.connectionQuery.connectionID}</h2>

<table id="header" class="sortable autostripe">
	<tbody>
		<tr>
			<td class="label" title="Unique ID for this connection">Connection
ID</td>
			<td>${requestContext.connectionQuery.connectionID}</td>
		</tr>
		<tr>
			<td class="label" tite="Hostname and port of the connected party">Remote
Address</td>
			<td>${row.remoteAddress}</td>
		</tr>
		<tr>
			<td class="label">Active</td>
			<td>${row.active}</td>
		</tr>
		<tr>
			<td class="label">Connected</td>
			<td>${row.connected}</td>
		</tr>
		<tr>
			<td class="label">Blocked</td>
			<td>${row.blocked}</td>
		</tr>
		<tr>
			<td class="label">Slow</td>
			<td>${row.slow}</td>
		</tr>
	</tbody>
</table>
-- 
View this message in context: http://old.nabble.com/How-to-get-the-consumer-or-producer%27s-ip-address--tp29478980p29491042.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.


Re: How to get the consumer or producer's ip address?

Posted by Torbjorn Kristoffersen <to...@gmail.com>.
On Thu, Aug 19, 2010 at 9:04 PM, Bruce Snyder <br...@gmail.com> wrote:
> On Thu, Aug 19, 2010 at 12:42 AM, oliver2010 <zz...@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.

Re: How to get the consumer or producer's ip address?

Posted by Bruce Snyder <br...@gmail.com>.
On Thu, Aug 19, 2010 at 12:42 AM, oliver2010 <zz...@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)U8V4\@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