[rabbitmq-discuss] [ Listen event when queue destroy from client ]

Michael Klishin mklishin at gopivotal.com
Mon Jul 7 13:56:33 BST 2014



On 7 July 2014 at 16:46:36, Hitesh Dobariya (hitesh at artoonsolutions.com) wrote:
> > 1) Amqp.js : This is the server in nodejs. when user connect to  
> server. server will generate the queue, and tell client to listen  
> to that queue in passive mode. in short client don't have access  
> for create queue. if i will listen from both side then queue will  
> not destroy automatically becuase my server (amqp.js) file's  
> queue consuming it. so i want that when client (queue.js) killed  
> or close. at that time server will notify that queue is destroyed,  
> and i will get all data like routing key when it destroy.

I think it's worth clarifying a few things. You do not consume in passive mode:
queue.declare is what takes the passive argument. If you want the server to generate
queue name and send it to the client for whatever reason, the use of
passive declare is fine.

>  
> Whereas amq.rabbitmq.event is the exchange, that will monitor  
> all the the events.
> connection.queue("eventListener", { exclusive: true } , function(q){  
> q.bind("amq.rabbitmq.event","");
>  
> //i want to listen all events here when queue destroy when client  
> app killed.
> q.subscribe(function (message, headers, deliveryInfo, messageObject)  
> {
> console.log(JSON.stringify(headers));
> })
> });

Two things that stand out: you bind using an empty routing key and not
"#". Perhaps that's just a typo.

If a client is "destroyed" (I assume it means it has disconnected, hibernated,
otherwise lost connection), only exclusive or auto-delete queues that had consumers
will be deleted. But then amq.rabbitmq.event will not have a message published
because it only tracks explicit queue.delete calls (I'm pretty sure this is the case but
Simon can correct me).

>  
> Above code will generate queue that will listen all the event  
> like exchange create, exchange delete, binding, queue created,  
> queue delete, etc..
> I read in the documentation of the amqp-event plugin that it will  
> deliver all the event which are happing to all exchanges on the  
> rabbitmq server.

Yes but this will not include queues deleted due to TTL, disconnect of
an exclusive queue owner, etc.

> 2) queue.js : it is the simple client that have only read access  
> to queue in passive mode only. if any event goes to this client  
> like queue delete then it's not helpful to me.

> My main purpose is to listen event and get message when queue.js  
> will be killed or application killed in android.

So your problem is effectively a presence one. This brings us back to
square one:

«If your problem is primarily client presence detection, there's presence exchange: 
https://github.com/tonyg/presence-exchange.»

 Note that RabbitMQ is not the optimal solution for tracking client presence.
Consider using a tool such as ZooKeeper or Redis.
--  
MK  

Staff Software Engineer, Pivotal/RabbitMQ


More information about the rabbitmq-discuss mailing list