[英]How to maintain SseEmitters list between multiple instances of a microservice?
Language: Spring Boot, JS语言:Spring Boot、JS
Overview : I am implementing server sent events functionality in my application which will be deployed in cloud foundry, wherein based on a new message in a queue(which I have subscribed in my micro-service), I will send some update to my client/browser(which is using EventSource).概述:我正在我的应用程序中实现服务器发送的事件功能,该功能将部署在 cloud foundry 中,其中基于队列中的新消息(我已在我的微服务中订阅),我将向我的客户端发送一些更新/浏览器(使用 EventSource)。 For this, I am maintaining a SseEmitters List(for mainitaining all the active SseEmitter) on my server side.为此,我在服务器端维护一个 SseEmitters 列表(用于维护所有活动的 SseEmitter)。 Once I receive a new message from the queue, based on the id(a field in the queue message), I will emit the message to corresponding client.一旦我从队列中收到一条新消息,我就会根据 id(队列消息中的一个字段)将消息发送给相应的客户端。
PROBLEM : How will the above scenario work, when I scale my application by creating multiple instances of it.问题:当我通过创建应用程序的多个实例来扩展我的应用程序时,上述场景将如何工作。 Since only one instance will receive the new queue message, it may happen that the active SseEmitter is not maintained in that particular instance, how do I solve this?由于只有一个实例会收到新的队列消息,因此可能会发生在该特定实例中未维护活动 SseEmitter的情况,我该如何解决?
To solve this problem, following approaches can be observed.为了解决这个问题,可以观察到以下方法。
If you think about it, knowing where your user (SSE Emitter) is, is like knowing where some website is.如果您考虑一下,知道您的用户(SSE Emitter)在哪里,就像知道某个网站在哪里一样。 You can use DNS-look-alike protocol to figure out where your user is.您可以使用 DNS-look-alike 协议来确定您的用户所在的位置。 Protocol would be as follows:协议如下:
If you're using messaging middleware for communication between your microservices, you can use routing feature which AMQP protocol provides.如果您使用消息传递中间件在微服务之间进行通信,则可以使用 AMQP 协议提供的路由功能。 Protocol would be as follows:协议如下:
Bindings are not resource intesive on modern AMQP brokers like RabbitMQ.绑定在像 RabbitMQ 这样的现代 AMQP 代理上不是资源密集型的。
Your question is old, and if you didnt figure this out by now, hope this helps.您的问题很老,如果您现在还没有弄清楚,希望这会有所帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.