Is there a messaging solution out there (preferably supporting Python) that I can use like a mailbox, 开发者_JS百科e.g. retrieve messages from any given queue without having to subscribe? I suppose message queues could work, but I would have to repeatedly subscribe, grab messages from the queue, then unsubscribe, which does not sound optimal.
Most (if not all) Messaging solutions support two modes of messaging
Publish \ Subscribe -that is, you need to subscribe to get the message.
Queuing - one party sends a message to the queue, the other reads the message from the Queue - no subscription needed, and the message is consumed when it's read.
Actually, standard Queuing is more common then publish subscribe - you have better chances of finding a tool that supports queuing, but not pub\sub, then find a tool that supports pub\sub but not queuing.
You are probably looking for the 2nd mode
There are quite a few options. Here are two:
Take a look at Redis. There are two Python client libraries for it (see redis-py and txRedis). The operation you describe (mailbox-like operations on queues), can be simulated by performing a
blpop
on a list in Redis.Another option is RabbitMQ. There are quite a few Python client libraries for it py-ampqlib and txAMQP. You can treat this as a mailbox-like queue by doing a
basic.get
andbasic.ack
(see this reference for more info).
RabbitMQ - http://www.rabbitmq.com
ZeroMQ - http://www.zeromq.org
Amazon SQS - http://aws.amazon.com/sqs
All three have libraries for python. The first two are free. SQS costs are pretty low if you don't send and receive millions of messages and it has the advantages of high availability and freeing you from the need to host manage it yourself.
Regarding subscription and unsubscription, if you're pulling from the queue rather than having the queue push messages to you (pub/sub) you're not subscribing and unsubscribing. In all the examples above you do not incur any overhead.
精彩评论