Subscribe/publish with Express js

时间:2019-02-24 03:14:05

标签: node.js rest express rpc

I have an Express js server that supplies weather forecast information to its clients. Right now, it's basically an RPC API where the client (a python client in this case) requests different types of weather info from different endpoints. This is fine for right now, but I was thinking about implementing a subscription model. Rather than connecting to different endpoints for different information, the client could just subscribe for the info that it wants and the server would send it every so often (obviously configurable by the client).

Is there a way to do this with express? Would I have to set up a server on the client side as well to listen for the publish events?

1 个答案:

答案 0 :(得分:1)

RabbitMQ是一个很好的选择,用于正确的目的。

我试图为您找到一个很好的教程作为参考,但是,我只用葡萄牙语找到了一个,但是如果您在google上搜索,就会发现其他英文版本。

但这很简单,就像您想要的那样,您将某个主题发布到队列中,并让其他客户端订阅该主题并处理消息

这里是链接 https://medium.com/@programadriano/rabbitmq-publish-subscribe-com-node-js-9363848f58fe