更新2015年8月:对于想要使用消息传递的人,我目前会推荐使用zeromq。可以用作pykka的补充或完全替代。如何发送RabbitMQ消息给Pykka演员?
我该如何聆听RabbitMQ队列中的消息,然后将它们转发给Pykka中的演员?
目前,当我尝试这样做时,我会发现奇怪的行为,系统停下来停下来。
这里是我有我的演员来实现:
class EventListener(eventlet.EventletActor):
def __init__(self, target):
"""
:param pykka.ActorRef target: Where to send the queue messages.
"""
super(EventListener, self).__init__()
self.target = target
def on_start(self):
ApplicationService.listen_for_events(self.actor_ref)
这里是我的ApplicationService
类应该检查队列新邮件里面方法:
@classmethod
def listen_for_events(cls, actor):
"""
Subscribe to messages and forward them to the given actor.
"""
connection = pika.BlockingConnection(pika.ConnectionParameters(host='localhost'))
channel = connection.channel()
channel.queue_declare(queue='test')
def callback(ch, method, properties, body):
message = pickle.loads(body)
actor.tell(message)
channel.basic_consume(callback, queue='test', no_ack=True)
channel.start_consuming()
好像start_consuming
无限期阻止。我有办法定期自行“轮询”队列吗?
你有什么特别的原因,你在一个程序中同时使用'pika'和'pykka'?似乎你可能会更好地使用自己的'pykka'。 – dano 2015-02-17 00:30:31
要重现此行为,请分享更多代码,如ApplicationServiceClass和其他相关代码吗? – Vinkal 2015-02-17 14:32:26
@dano我需要并发进程在对队列消息的响应中运行。 (想想某种密集的数据分析)。 – drozzy 2015-02-19 02:30:04