简体   繁体   English

作为Kafka消费者的节点

[英]Node as Kafka consumer

I have searched for packages for Node like this: https://www.npmjs.com/package/kafka and https://www.npmjs.com/package/no-kafka 我已经搜索了像这样的Node包: https : //www.npmjs.com/package/kafkahttps://www.npmjs.com/package/no-kafka

My question is: Do these packages makes the node.js subscribe to kafka all the time? 我的问题是:这些程序包是否使node.js始终都订阅kafka? or Do I need some packages like forever or pm2 to achieve that? 还是我需要永久或pm2之类的软件包才能实现这一目标?

The purpose of something like forever is to keep your node app running all the time (if it should crash). forever这样的目的是使节点应用程序始终保持运行(如果它应该崩溃)。

This is pretty much separate from what those two packages do or don't do. 这与这两个软件包执行或不执行的操作几乎是分开的。 They run inside your node app. 它们在您的节点应用程序中运行。 If you want them to run all the time, then you need them to be used in a node app that is always running. 如果希望它们一直运行,则需要在始终运行的节点应用程序中使用它们。

You can either write a rock solid node app that doesn't ever crash so it runs continually or you can attempt to do that and also run something like forever so that if your app dies, forever will automatically restart it. 您可以编写一个永远不会崩溃的坚如磐石的节点应用程序,使其连续运行,也可以尝试执行该操作,还可以永久运行类似的东西,这样,如果您的应用程序死了,永久地会自动重新启动它。

Do these packages makes the node.js subscribe to kafka all the time? 这些软件包是否使node.js一直都订阅kafka? or Do I need some packages like forever or pm2 to achieve that? 还是我需要永久或pm2之类的软件包才能实现这一目标?

No. forever and pm2 have no influence on what kafka does or doesn't do. forever不会,而pm2对kafka做或不做的事情没有影响。 They just make sure your app is restarted if it crashes or exits for some reason. 他们只是确保您的应用由于某种原因崩溃或退出时会重新启动。


If you are using the consumer side of the kafka API, then you will have to do some research and testing to see how good the library is at keeping you connected all the time, even when the server you are connecting to temporarily restarts or there is a temporary internet glitch. 如果您使用的是kafka API的用户端,那么您将必须进行一些研究和测试,以查看该库在保持您始终保持连接状态方面的良好表现,即使您要连接的服务器暂时重启或暂时的互联网故障。

From what I can tell looking at the code for this implementation , if there's an error on an open connection, the connection is just closed and there is no reconnect logic so you would probably have to write reconnect logic by subscribing to either the error or close events and then attempting to reconnect when the connection is lost. 从我可以告诉看的代码此实现 ,如果有一个打开的连接上的错误,连接被刚刚闭幕,没有重新连接逻辑,那么你可能需要编写通过订阅要么重新连接逻辑errorclose事件,然后在连接断开时尝试重新连接。

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

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