rabbit.js icon indicating copy to clipboard operation
rabbit.js copied to clipboard

Garbage collection of server objects

Open squaremo opened this issue 11 years ago • 0 comments

It's desirable that rabbit.js doesn't leave garbage around on the server. For instance, that a queue declared implicitly by sockets connecting is removed when all sockets are disconnected (well, perhaps after a grace period, so we don't lose messages accidentally).

When consuming from a queue, this is pretty easy: mark the queue as auto-delete (or give a queue a TTL), so when all sockets have gone, their consumer tags go, and the queue goes. Similarly exchanges and bindings.

From the publishing side it is not easy.

One scheme I have thought of is to represent a publisher's "lease" on an exchange by a queue bound to it, with its fate tied to the socket. We don't actually want messages in the queue, so it should have a queue-based TTL of 0, and no consumer, and a binding key unlikely to match routing keys.

So far so good. I can't adopt this tactic with queues, however. Probably the closest I can come is to declare a queue with a TTL, and occasionally redeclare it. Which is a bit gross, and will lead to a lot of redundant queue.declares, if there are a lot of sockets. (Also I have to think of what to do if the queue.declare fails!)

squaremo avatar Mar 04 '14 15:03 squaremo