Kafka 和 NodeJS 的实时通知 [英] Real time notification with Kafka and NodeJS

查看:37
本文介绍了Kafka 和 NodeJS 的实时通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的项目中,我必须设计一个实时通知系统.我按照下图做了.

In my project, I have to design a real time notification system. And I did it as the image below.

你可以看到我使用 Kafka 作为队列消息系统,使用 NodeJS 构建 Websocket Server 和 Kafka Consumers.生产者将收集通知数据并将其推送到 Kafka.如果数据属于该用户,消费者将从 Kafka 读取并处理数据,并通过 websocket 将其推送到客户端.

You can see that I used Kafka as a queue messaging system, and NodeJS to build Websocket Server and Kafka Consumers. Producers will collect the notification data and push it to Kafka. Consumers will read and process the data from Kafka and push it to client via websocket if that data belongs to that user.

有了上面的架构师,每个在线用户都会打开一个Websocket连接并创建一个新的Consumer.这意味着如果有 10 万用户在线,我们必须有 10 万消费者.

With the architect above, Each online user will open a Websocket connection and create a new Consumer. It means that if there are 100K user online, we have to have 100K Consumers.

所以我的问题是上面的设计是实时通知系统的正确设计吗?你有什么不同的想法吗?如果我有 100K 消费者,有什么问题吗?

So my question is the design above is a correct design for a real time notification system? Do you have any different idea? Is there any issue if I have 100K Consumer?

已编辑

它不应该打开太多消费者.它能够与消费者和 websockets 一起工作

It should not open too many consumers. It is able to work with a consumer and websockets

推荐答案

你的设计是正确的,如果你想一直和你的每个客户端保持连接那么你必须保持相同数量的客户端-websocket 因为有很多客户端;但是对于连接的客户端,消费者不必增加;因为它们可以在不同的 client-websockets 之间共享.

Your design is correct, if you want to be connected with each of your client all the time then you will have to keep the same number of client-websocket as there are number of clients; but consumer doesn't have to be increased with respect to the clients connected; since they can be shared among the different client-websockets.

这取决于您的应用程序和您想要的处理方式.

It depends on your application and the way you want to handle it.

这篇关于Kafka 和 NodeJS 的实时通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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