简体   繁体   English

Ruby中的监听器:Bunny Gem或AMQP gem

[英]Listener in Ruby: Bunny Gem or AMQP gem

I want to make a listener in Ruby which will read messages from a channel on every half-an-hour. 我想在Ruby创建一个监听器,它将每半小时从一个通道读取消息。 I am confused on which Gem to use: Bunny ( https://github.com/ruby-amqp/bunny ) or AMQP ( http://rubyamqp.info )? 我对使用哪种宝石感到困惑: Bunnyhttps://github.com/ruby-amqp/bunny )或AMQPhttp://rubyamqp.info )? I am aware that Bunny is easy-to-use. 我知道Bunny很容易使用。 But will that solve my purpose? 但这会解决我的目的吗?

How will your script be triggered? 你的脚本将如何被触发? What's the volumes in question? 有问题的卷是什么? Will the processing be done sequentially or in some sort of event-based system? 处理是按顺序完成还是在某种基于事件的系统中完成? Both libraries are essentially the same - except for one core difference. 两个库基本相同 - 除了一个核心差异。

Bunny is used for sequential processing. Bunny用于顺序处理。 A message is popped off the queue, processed then acknowledged, before the next message is retrieved. 在检索下一条消息之前,会从队列中弹出一条消息,然后进行处理,然后进行确认。 To scale this, you should use either threads or processes to process more messages at once. 要扩展此功能,您应该使用线程或进程一次处理更多消息。

The AMQP gem is Event-based and runs inside an EventMachine reactor. AMQP gem是基于事件的,并在EventMachine反应器内运行。 This is ideally suited to light workloads where RabbitMQ or another external service would be the bottleneck. 这非常适合于轻度工作负载,其中RabbitMQ或其他外部服务将成为瓶颈。 Using AMQP gem, a consumer will consume as many messages as possible (or told to), and fire off individual callbacks for each message. 使用AMQP gem,消费者将消耗尽可能多的消息(或告知),并为每条消息触发单个回调。 If the callbacks make their own network calls, this is probably the best solution as it allows Ruby to interleave the network communication most effectively. 如果回调进行自己的网络调用,这可能是最好的解决方案,因为它允许Ruby最有效地交错网络通信。

Short summary, but basically for a rarely-running script I'd suggest the sequential nature of Bunny, especially if you've not worked in EventMachine before. 简短的总结,但基本上对于一个很少运行的脚本,我建议Bunny的顺序性,特别是如果你之前没有在EventMachine中工作过。 It's hard to answer fully without knowledge of your workload. 如果不了解您的工作量,很难完全回答。

Take a look at jondot/sneakers for a ready-made Bunny framework. 看看jondot /运动鞋是否有现成的Bunny框架。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM