You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@qpid.apache.org by fadams <fr...@blueyonder.co.uk> on 2011/06/17 16:08:42 UTC

Is it possible to write a client that gets notified of connections/disconnections to broker?

Hello all,
I'd like to write a client that connects to the c++ broker and
asynchronously gets notified of other connection attempts being made to the
broker.

The idea is that this client can write audit logs that shows info about
connections IP address, queues, bindings, connection time etc.

I'm guessing that it's going to involve QMF so some of Gordon Sim's recent
QMF2 Java Examples are going to help me I'm sure, but the last piece in the
puzzle is really how do I get notified asynchronously.

I guess that I could poll and maintain differences of queues etc. but it is
more elegant if I could be notified of connections/disconnections.

Many thanks.





--
View this message in context: http://apache-qpid-users.2158936.n2.nabble.com/Is-it-possible-to-write-a-client-that-gets-notified-of-connections-disconnections-to-broker-tp6487251p6487251.html
Sent from the Apache Qpid users mailing list archive at Nabble.com.

---------------------------------------------------------------------
Apache Qpid - AMQP Messaging Implementation
Project:      http://qpid.apache.org
Use/Interact: mailto:users-subscribe@qpid.apache.org


Re: Is it possible to write a client that gets notified of connections/disconnections to broker?

Posted by Gordon Sim <gs...@redhat.com>.
On 06/20/2011 01:49 PM, Gordon Sim wrote:
> On 06/19/2011 08:30 AM, fadams wrote:
>> Secondly you said "The messages you receive on that will be amqp-list
>> formatted messages". It seems that Events are actually amqp-map formatted
>> (the QMF Wiki says "_data_indication List of<qmf.content> " too, but this
>> seems to be wrong given what I've seen in practice).
>
> What version of the broker are you using? It certainly seems to be a
> list message for me on trunk.

Just fyi: I just discovered this myself, but for 0.8 the broker does 
indeed send out map messages. From 0.10 it is list messages however, 
presumably allowing for more than one event per message(?).

---------------------------------------------------------------------
Apache Qpid - AMQP Messaging Implementation
Project:      http://qpid.apache.org
Use/Interact: mailto:users-subscribe@qpid.apache.org


Re: Is it possible to write a client that gets notified of connections/disconnections to broker?

Posted by Gordon Sim <gs...@redhat.com>.
On 06/19/2011 08:30 AM, fadams wrote:
> Hi again Gordon et al.
>
> I'm making progress with this :-) so thanks for all the info so far.
>
> Firstly with respect to the topic being subscribed to for events
> "qmf.default.topic/agent.ind.event.org_apache_qpid_broker.#" is this
> actually documented anywhere?

Quite possibly not, I discovered things mainly be looking at the code of 
the broker and existing management tools. It is something we need to 
write up better. If you have any contributions there that would be great.

> I had a look through the QMF Wiki pages but
> couldn't seen any info at all on the topics used by QMF (it also seems to
> use qmf.default.direct for request/response - but again I can't find any
> documentation).
>
> I'd have never worked that stuff out without your help.......
>
> Secondly you said "The messages you receive on that will be amqp-list
> formatted messages". It seems that Events are actually amqp-map formatted
> (the QMF Wiki says "_data_indication 	List of<qmf.content>  " too, but this
> seems to be wrong given what I've seen in practice).

What version of the broker are you using? It certainly seems to be a 
list message for me on trunk.

> See the following snippet from my hacky onMessage()
>
> 	public void onMessage(Message message) {
> 		try {
> 			MapMessage msg = (MapMessage)message;
>
> 			Map schemaId = (Map)msg.getObject("_schema_id");
> 			String className = new String((byte[])schemaId.get("_class_name"));
>
> 			System.out.println(className);

So the JMS client is returning map messages to you? Can you get a broker 
trace for a simple case of that?
	
>
> I'll keep you all posted and if I get anything worthwhile put together I'll
> post it.

Excellent!

---------------------------------------------------------------------
Apache Qpid - AMQP Messaging Implementation
Project:      http://qpid.apache.org
Use/Interact: mailto:users-subscribe@qpid.apache.org


Re: Is it possible to write a client that gets notified of connections/disconnections to broker?

Posted by fadams <fr...@blueyonder.co.uk>.
Hi again Gordon et al.

I'm making progress with this :-) so thanks for all the info so far.

Firstly with respect to the topic being subscribed to for events
"qmf.default.topic/agent.ind.event.org_apache_qpid_broker.#" is this
actually documented anywhere? I had a look through the QMF Wiki pages but
couldn't seen any info at all on the topics used by QMF (it also seems to
use qmf.default.direct for request/response - but again I can't find any
documentation).

I'd have never worked that stuff out without your help.......

Secondly you said "The messages you receive on that will be amqp-list
formatted messages". It seems that Events are actually amqp-map formatted
(the QMF Wiki says "_data_indication 	List of <qmf.content> " too, but this
seems to be wrong given what I've seen in practice).

See the following snippet from my hacky onMessage()

	public void onMessage(Message message) {
		try {
			MapMessage msg = (MapMessage)message;

			Map schemaId = (Map)msg.getObject("_schema_id");
			String className = new String((byte[])schemaId.get("_class_name"));

			System.out.println(className);	

I'll keep you all posted and if I get anything worthwhile put together I'll
post it.

Cheers,
Fraser



Gordon Sim wrote:
> 
> 
> You can create a receiver/message consumer with address 
> qmf.default.topic/agent.ind.event.org_apache_qpid_broker.#
> 
> The messages you receive on that will be amqp-list formatted messages 
> (from JMS you would need to decode these as per my previous example as 
> the library won't yet do it for you). Each entry will be an event 
> represented as a map.
> 
> event["_schema_d"]["_class_name"] will contain the class of the event. 
> In your case you are interested in clientConnect and clientDisconnect 
> 
> 



--
View this message in context: http://apache-qpid-users.2158936.n2.nabble.com/Is-it-possible-to-write-a-client-that-gets-notified-of-connections-disconnections-to-broker-tp6487251p6492378.html
Sent from the Apache Qpid users mailing list archive at Nabble.com.

---------------------------------------------------------------------
Apache Qpid - AMQP Messaging Implementation
Project:      http://qpid.apache.org
Use/Interact: mailto:users-subscribe@qpid.apache.org


Re: Is it possible to write a client that gets notified of connections/disconnections to broker?

Posted by fadams <fr...@blueyonder.co.uk>.
Many thanks Gordon. I'll give that a go over the weekend.



Gordon Sim wrote:
> 
> 
> You can create a receiver/message consumer with address 
> qmf.default.topic/agent.ind.event.org_apache_qpid_broker.#
> 
> The messages you receive on that will be amqp-list formatted messages 
> (from JMS you would need to decode these as per my previous example as 
> the library won't yet do it for you). Each entry will be an event 
> represented as a map.
> 
> event["_schema_d"]["_class_name"] will contain the class of the event. 
> In your case you are interested in clientConnect and clientDisconnect 
> (events are defined in qpid/specs/management.xml).
> 
> Let me know if you have trouble with this and I'll try to knock up a JMS 
> example.
> 
> 
> ---------------------------------------------------------------------
> Apache Qpid - AMQP Messaging Implementation
> Project:      http://qpid.apache.org
> Use/Interact: mailto:users-subscribe@qpid.apache.org
> 


--
View this message in context: http://apache-qpid-users.2158936.n2.nabble.com/Is-it-possible-to-write-a-client-that-gets-notified-of-connections-disconnections-to-broker-tp6487251p6487409.html
Sent from the Apache Qpid users mailing list archive at Nabble.com.

---------------------------------------------------------------------
Apache Qpid - AMQP Messaging Implementation
Project:      http://qpid.apache.org
Use/Interact: mailto:users-subscribe@qpid.apache.org


Re: Is it possible to write a client that gets notified of connections/disconnections to broker?

Posted by Gordon Sim <gs...@redhat.com>.
On 06/17/2011 03:08 PM, fadams wrote:
> Hello all,
> I'd like to write a client that connects to the c++ broker and
> asynchronously gets notified of other connection attempts being made to the
> broker.
>
> The idea is that this client can write audit logs that shows info about
> connections IP address, queues, bindings, connection time etc.
>
> I'm guessing that it's going to involve QMF so some of Gordon Sim's recent
> QMF2 Java Examples are going to help me I'm sure, but the last piece in the
> puzzle is really how do I get notified asynchronously.
>
> I guess that I could poll and maintain differences of queues etc. but it is
> more elegant if I could be notified of connections/disconnections.

You can create a receiver/message consumer with address 
qmf.default.topic/agent.ind.event.org_apache_qpid_broker.#

The messages you receive on that will be amqp-list formatted messages 
(from JMS you would need to decode these as per my previous example as 
the library won't yet do it for you). Each entry will be an event 
represented as a map.

event["_schema_d"]["_class_name"] will contain the class of the event. 
In your case you are interested in clientConnect and clientDisconnect 
(events are defined in qpid/specs/management.xml).

Let me know if you have trouble with this and I'll try to knock up a JMS 
example.


---------------------------------------------------------------------
Apache Qpid - AMQP Messaging Implementation
Project:      http://qpid.apache.org
Use/Interact: mailto:users-subscribe@qpid.apache.org