1

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?

Tom Erik Støwer
  • 1,399
  • 9
  • 19

1 Answers1

0

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.

jgato
  • 181
  • 1
  • 6
  • Thanks. The relevant part of this answer is the first part, as I have explained the problem with the second part in my original question. I was not aware of the possibility of using connection.queues[name] but that certainly solved it :-) – Tom Erik Støwer Mar 12 '14 at 21:19