谁能告诉我 python 中 pika 和 kombu 消息传递库之间有什么区别? [英] Can anyone please tell me what are the differences between pika and kombu messaging library in python?

查看:15
本文介绍了谁能告诉我 python 中 pika 和 kombu 消息传递库之间有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的应用程序中使用消息传递库与 rabbitmq 进行交互.谁能解释一下 pika 和 kombu 库之间的区别?

I want to use messaging library in my application to interact with rabbitmq. Can anyone please explain the differences between pika and kombu library?

推荐答案

Kombu 和 pika 是两个不同的 Python 库,它们从根本上服务于相同的目的:向/从消息代理发布和消费消息.

Kombu and pika are two different python libraries that are fundamentally serving the same purpose: publishing and consuming messages to/from a message broker.

Kombu 比 pika 具有更高的抽象级别.Pika 仅支持 AMQP 0.9.1 协议,而 Kombu 可以支持其他传输(例如 Redis).更一般地说,Kombu 比 pika 功能更丰富.它支持重新连接策略、连接池、故障转移策略等.其中一些功能是必备的(如果您选择在严肃的项目中使用 Pika,则必须重新实现或解决这些功能),而其他一些功能则很好.这样做的缺点是:一个库越复杂,你就越会对它的行为感到惊讶,也就越难推理和跟踪错误.Pika 的代码库相对较小且易于使用.另一方面,Kombu 是为 Celery 量身定制的,这是一个巨大的项目.Celery 的文档相当不错,但 Kombu 的文档相比之下就很差了.感觉 Celery 是打算公开的项目,而不是 Kombu.

Kombu has a higher level of abstraction than pika. Pika only supports AMQP 0.9.1 protocol while Kombu can support other transports (such as Redis). More generally, Kombu is more feature-rich than pika. It has support for reconnection strategies, connections pooling, failover strategies, among others. Some of those features are must-haves (that you'll have to re-implement or work around if you choose to use Pika in a serious project), some other are just nice to have. The downside of this: the more complex is a library, the more you will be surprised by its behavior and the harder it will be to reason about and trace bugs. Pika's codebase is relatively small and easy to get into. On the other hand, Kombu is tailor made for Celery which is a huge project. Celery's documentation is rather good, yet Kombu's documentation is quite poor in comparison. It feels like Celery is the project intended to be exposed, not Kombu.

在底层,当使用 AMQP 作为传输时,Kombu 使用 py-amqp 库或librabbitmq 发送/接收/解析 AMQP 0.9.1 帧.在这方面,pika 在抽象级别上比 Kombu 更接近 py-amqp.

Under the hood, when using AMQP as transport, Kombu uses either py-amqp library or librabbitmq to send/receive/parse AMQP 0.9.1 frames. In this respect, pika would be closer to py-amqp than Kombu in term of abstraction level.

RabbitMQ 很复杂.如果您认为不应在已经很好封装的功能上增加复杂性,或者如果您需要对 RabbitMQ 进行更多控制和理解,请选择 pika.如果您需要一个交钥匙解决方案并且不想重新发明轮子(即重新实现一些在大多数情况下值得几行代码的基本功能),请选择 Kombu.但是,无论您选择什么库,都不应该让您无需深入了解底层代理的优势和局限性.

RabbitMQ is complex. Choose pika if you think that you shouldn't add complexity over features that are well encapsulated already, or if you need more control and understanding over RabbitMQ. Choose Kombu if you need a turnkey solution and don't want to reinvent the wheel (i.e. reimplement some basic features which are worth a few lines of codes most of the time). But whatever library you choose, it shouldn't dispense your from learning in depth the advantages and limitations of the underlying broker.

这篇关于谁能告诉我 python 中 pika 和 kombu 消息传递库之间有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆