I have some requirements for a system in need of a message queue:
- The subscribers shall get individual queues.
- The individual queues shall NOT be deleted when the subscriber disconnects
- The subscriber shall be able to reconnect to its own queue if it looses connection
- Only the subscriber shall be able to use the queue assigned to it
- Nice to have: the queues survive a server restart
Can RabbitMQ be used to implement this, and i开发者_如何学Pythonn that case how?
I have only recently started using Rabbit but I believe your requirements can be addressed fairly easily. 1) I have implemented specific queues for individual subscribers by having the subscriber declare the queue (and related routing key) using its machine name as part of the queue name. The exchange takes care of routing messages appropriately by way of the binding/routing keys. In my case, all subscribers get a copy of the same message posted by the publisher and an arbitrary number of subscribers can declare their own queues and start receiving messages.
2) That's pretty much standard. If you declare a queue then it will remain in the exchange, and if it is set as durable then it will survive broker restarts. In any case, your subscriber should call queue.Declare() at startup to ensure that the queue exists but in terms of the subscriber disconnecting, the queue will remain.
3) If the queue is there and a subscriber is listening to that queue by name then there's no reason why it shouldn't be able to reconnect.
4) I haven't really delved in to the security aspects of Rabbit yet. There may be a means of securing individual queues though I'll let someone else comment on this as I'm no authority.
5) See (2). Messages will also survive a restart if set as durable as they are then written to disk. This incurs a performance penalty as there's disk I/O but that's kind of what you'd expect.
So basically, yes. Rabbit can do as you ask. In terms of 'how', there are varying degrees of 'how'. Will happily try to provide you with code-level answers should you have trouble implementing any of the above. In the meantime, and if you haven't already done so, I suggest reading through the docs: http://www.rabbitmq.com/documentation.html
HTH. Steve
精彩评论