[rabbitmq-discuss] Enforcing single connection to a queue

RoLo spamfodder42 at gmail.com
Thu Apr 19 21:27:10 BST 2012

I'm working on a project where we need to enforce only a single client
connection to a queue.  Worse, the queue has to persist when the connection
closes, which rules out using the exclusive bit as the AMQP spec states that
an exclusive queue will always be auto-deleted when the client terminates

We've decided to use RabbitMQ.  After extensive searching, I haven't found
anything on the RabbitMQ side to enforce this requirement.  If there is, I'd
love to hear about it.

In the meantime, I've tried forging ahead with an attempt to implement this
manually.  We have a 'control' server which handles creating some special
exchanges and queues on the fly and which will handle some authentication
(outside of the AMQP authentication mechanisms).  The idea was to mark a
connection to the server for a specific user.  So the user authenticates
against our server, the server notes what connection the user is using and
on subsequent authentication requests by that user, we check the existence
of a live connection and if there is one, we kill it.  Our server is talking
to RabbitMQ via it's REST API, and the rest API needs the connection name in
order to DELETE a connection:

/api/connections/name	An individual connection. DELETEing it will close the

The problem is getting the connection name, it seems impossible.  The
connection name isn't sent back to the client so the client cannot report it
and the API to fetch all connections from the server doesn't expose anything
unique to the user.  We can't use IP because people may be behind a NATted
firewall, and besides that, we wouldn't know which connection to kill as at
that point the user would have two connections live, the zombie connection
and the new connection which is making the authentication request.  We need
a timestamp, which isn't there.

At this point, we're looking at inserting some custom properties (UID,
Timestamp) in the client_properties when the client initiates the
connection.  The server will parse the parameters and record them against
the user.  When a new authentication request comes in, the server will fetch
the list of connections from RabbitMQ via the REST API, and try to match the
UID and Timestamp, then pull the connection name and kil the old connection.

So I think there's a solution, but it's been a uphill battle to iron this
out.  I'm just curious if there is an easier way to do this that I'm just
not seeing as I'm fairly new to AMQP.  Input appreciated!
View this message in context: http://old.nabble.com/Enforcing-single-connection-to-a-queue-tp33716781p33716781.html
Sent from the RabbitMQ mailing list archive at Nabble.com.

More information about the rabbitmq-discuss mailing list