Question

I'm using the node-amqp module to manage rabbitmq subscriptions. Specifically, I'm assigning an exclusive/private queue to each user/session, and providing binding methods through the REST interface. I.e. "bind my queue to this exchange/routing_key pair", and "unbind my queue to this exchange/routing_key pair".

The challenge here is to avoid keeping a reference to the queue object in memory (say, in an object with module-wide scope).

Simply retrieving the queue itself from the connection each time I need it, proved difficult, since the queue object keeps tabs on bindings internally, probably to avoid violating the following from the amqp 0.9.1 reference:

The client MUST NOT attempt to unbind a queue that does not exist. Error code: not-found

I tried to simply set the queue object as a property on a session object using connect-mongo, since it uses JSON.stringify/JSON.parse on its properties. Unfortunately, the queue object fails to "stringify" due to a circular structure.

What is the best practice for persisting a queue object from the node-amqp module? Is it possible to serialize/deserialize?

Was it helpful?

Solution

I would not try to store the queue object, instead of that use an unique name for the queue that you can store. After that whenever you want to make operations over the queue you have two options:

  • In the case you have a previously opened "channel" to the queue, you should be able to do:

    queue = connection.queues[name]. 
    

    I mean connection as a node-amqp connection against rabbitMQ.

  • In the case you dont have a channel opened in your connection with rabbitmq, just open the channel again:

    connection.queue(name = queueName, options, function(queue) {
        // for example do unbind
    })
    

I am also using REST interface to manage rabbitMQ. My connection object maintains all the queues, channels, etc... So, only the first time I try to use a queue I call to connection.queue, and the following request just retrieve the queue through connection.queues.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top