amqp vs amqplib - 哪个 Node.js amqp 客户端库更好?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20128124/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 16:19:28  来源:igfitidea点击:

amqp vs amqplib - which Node.js amqp client library is better?

node.jsrabbitmqamqp

提问by Javier del Saz

What are the differences between those amqp client libraries? Which one is the most recommended? What are the major differences?

这些 amqp 客户端库之间有什么区别?最推荐哪一款?主要区别是什么?

回答by Carl H?rberg

I would recommend amqp.nodeand bramqpover node-amqp. node-amqp has a lot of bugs and is poorly maintained, and it hides the "channel" concept which introduces a lot of problems for rabbitmq servers (because they are never closed).

我会推荐amqp.nodebramqp 而不是 node-amqp。node-amqp有很多bug,维护不善,它隐藏了“通道”概念,这给rabbitmq服务器带来了很多问题(因为它们永远不会关闭)。

回答by bakkerthehacker

I'm the guy that wrote the bramqp library. So I'm going to admit from the start I may be a bit biased. :P

我是编写 bramqp 库的人。所以我从一开始就承认我可能有点偏见。:P

In my opinion, as long as you know the spec, bramqpshould work fine. Otherwise, use amqp.node

在我看来,只要您了解规范,bramqp 就可以正常工作。否则,使用amqp.node



The following are the amqp libraries available for node.js.

以下是可用于 node.js 的 amqp 库。

amqplib/ amqp.node- promise style, still updated, looks pretty stable and easy

amqplib/ amqp.node- 承诺风格,仍在更新,看起来非常稳定和简单

bramqp- provides a full low level access to AMQP functions, not recommended for starting out

bramqp- 提供对 AMQP 功能的完整低级访问,不建议开始使用

amqp-coffee- coffeescript implementation similar to amqp/node-amqp

amqp-coffee- 类似于 amqp/node-amqp的咖啡脚本实现

amqp/ node-amqp- popular, fixed API, not updated as often, a few odd bugs, stable but limited

amqp/ node-amqp- 流行的,固定的 API,不经常更新,一些奇怪的错误,稳定但有限



The following libraries use one of the previous libraries, while providing an easier to use interface or adding features

以下库使用以前的库之一,同时提供更易于使用的界面或添加功能

rabbit.jsuses amqplib/amqp.node

rabbit.js使用 amqplib/amqp.node

wascallyuses amqplib/amqp.node

wascally使用 amqplib/amqp.node

amquses amqplib/amqp.node

amq使用 amqplib/amqp.node

amqpeauses bramqp

amqpea使用 bramqp

easy-amqpuses amqp/node-amqp

easy-amqp使用 amqp/node-amqp

rabbususes wascally

rabbus使用 wascally



I am also going to add node-amqp10separately, as it can connect to amqp 1.0 servers.

我还将单独添加node-amqp10,因为它可以连接到 amqp 1.0 服务器。

If there are any more that I should add, just let me know.

如果还有什么我应该补充的,请告诉我。

回答by sheldonk

I have been using node-amqp

我一直在使用node-amqp

npm install amqp

This is the one recommended by RabbitMQwhich is why I've been using it. From what I've been doing, this module is more dry and readable compared to the other libraries I have seen.

这是RabbitMQ推荐的,这就是我一直在使用它的原因。从我一直在做的事情来看,与我见过的其他库相比,这个模块更加枯燥和可读。

回答by EaminZ

I used both for a while. At the first glance, it might seem that node-amqp (amqp) is more adequate but it actually has so many bugs and no one is fixing them. For instances,

我用了一段时间。乍一看,node-amqp (amqp) 似乎更合适,但实际上它有很多错误,而且没有人修复它们。为实例,

  1. RabbitMQ's MQTT and STOMP adapter should allow communication between clients using those 2 protocols with clients using AMQP, but node-amqp just fails to parse messages sent by MQTT or STOMP, while amqp.node (amqplib) can.
  2. node-amqp (amqp) has implemented auto-reconnecting and so doesn't throw exceptions on accidental disconnection. That means you will be forced to use the built-in reconnecting, you can't detect disconnection and handle it yourself. However, its reconnecting always double the number of connections. It will exhaust both client and server eventually. I'd rather code my own reconnecting function with amqp.node (amqplib).
  1. RabbitMQ 的 MQTT 和 STOMP 适配器应该允许使用这两种协议的客户端与使用 AMQP 的客户端进行通信,但是 node-amqp 只是无法解析 MQTT 或 STOMP 发送的消息,而 amqp.node (amqplib) 可以。
  2. node-amqp (amqp) 已实现自动重新连接,因此不会在意外断开连接时引发异常。这意味着您将被迫使用内置的重新连接,您无法检测到断开连接并自行处理。但是,它的重新连接总是使连接数增加一倍。它最终会耗尽客户端和服务器。我宁愿用 amqp.node (amqplib) 编写我自己的重新连接函数。

I tested it with broker provided by www.robomq.io, it's a good one so the blame should be of the library. Implementing a perfect library in Node.js is tough though.

我用 www.robomq.io 提供的代理对其进行了测试,这是一个很好的代理,因此应该归咎于图书馆。但是在 Node.js 中实现一个完美的库是很困难的。

By the way, you can find a full set of example code using amqp.node (amqplib) in 5 scenarios at https://github.com/robomq/robomq.io/tree/master/sdk/AMQP/Node.jsand the documentation at http://robomq.readthedocs.org/en/latest/one-one/#nodejs.

顺便说一下,您可以在https://github.com/robomq/robomq.io/tree/master/sdk/AMQP/Node.js和5 个场景中找到使用 amqp.node (amqplib) 的全套示例代码和http://robomq.readthedocs.org/en/latest/one-one/#nodejs 上的文档。

回答by cressie176

https://github.com/guidesmiths/rascal#rascalworth a mention too. It's built on top of amqplib, and has a set of useful features like auto reconnection logic, configuration based subscription / publication and good support for TDD.

https://github.com/guidesmiths/rascal#rascal 也值得一提。它建立在 amqplib 之上,并具有一组有用的功能,例如自动重新连接逻辑、基于配置的订阅/发布以及对 TDD 的良好支持。

回答by SagarM

This question probably requires an updated answer in 2020.

这个问题可能需要在 2020 年更新答案。

You may still refer to bakkerthehacker's answer as to what the different libraries do.

您仍然可以参考 bakkerthehacker 对不同库的作用的回答。

In 2020:

2020年:

  1. amqpdoesn't seem to be supported anymore. It was last published 2 years ago.
  2. For AMQP 0-9-1 protocol, amqplibis the most widely used library.
  3. For AMQP 1.0 protocol, you could go with rhea.
  1. amqp似乎不再受支持。上次发布是在 2 年前。
  2. 对于 AMQP 0-9-1 协议,amqplib是使用最广泛的库。
  3. 对于 AMQP 1.0 协议,您可以使用rhea

回答by Flexpadawan

Just started learning rabbitmq myself. I've found from other blogs that ampq.node is well accepted. Another one that I've found (not tested) is from wascally. https://github.com/LeanKit-Labs/wascally

自己刚开始学习rabbitmq。我从其他博客中发现 ampq.node 被广泛接受。我发现的另一个(未测试)来自 wascally。https://github.com/LeanKit-Labs/wascally