Pubsub,推送到所有Cloud Run容器 [英] Pubsub, push to all Cloud Run containers

查看:50
本文介绍了Pubsub,推送到所有Cloud Run容器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Pubsub(push)和Cloud Run,将在其中部署使用Spring Boot构建的Java应用程序.

I am using Pubsub(push) and Cloud Run, where I will deploy a Java application built with Spring Boot.

我有两种情况.假设由于负载大,我在Cloud Run中运行了10个容器/实例的 Service A .我要:

I have two cases. Let's say I have Service A running in Cloud Run with 10 containers/instances, due to high load. I want to:

  • 将消息(来自Cloud Function)推送到 all (广播) Service A
  • 的容器
  • 将消息(来自Cloud Function)推送到 Service A
  • 单个任意容器

背景:我的Cloud Run服务将使用服务器发送事件将数据直接推送到客户端/浏览器.这当然意味着容器/实例将保持状态.在某些情况下,我需要将消息推送到所有容器上的所有sse/ws连接(想象一个带有公共聊天室的聊天应用程序,每个人都可以看到发布的消息).由于Cloud Run中的容器无法相互了解或看到对方(我假设),因此我想出解决此问题的正确方法是使用pubsub.

Background: My Cloud Run service will be using server-sent-events to push data directly to the client/browser. This of course means the containers/instances will keep a state. There are cases where I need to push a message to all sse/ws connections on all containers(imagine a chat application with a public chat room, where everyone can see a published message). Since there are no way for the containers in Cloud Run to know or see each other(I assume), I figured the right way to solve this is using pubsub.

如果有更适合这种情况的工具,请指出正确的方向.

Please point me in the right direction if there are tools that suits this situation better.

推荐答案

Cloud Run实例是独立的,正如您所说的,它们看不见彼此.另外,Cloud Run合同要少一些状态,因此不能有状态并在推送消息中进行更新.

Cloud Run instances are independent and as you said they can't see and know each others. In addition, Cloud Run contract is to be state less, and so can't have state and update it in push message.

实例可以是活动的,也可以是非活动的(正在处理或不请求),如果您有10个当前活动实例,则可能预先(启动)准备了20或30个实例以吸收流量的增加(如果发生).

Instances can be active and inactive (processing or not requests) and if you have 10 current active instance, there is maybe 20 or 30 instances provisioned in advance (started) to absorb the traffic increase (if happen).

所有这些都表明您的设计是错误的.您无需依赖Cloud Run实例的状态,也不必考虑通过推送对其进行更新.

All of this to say that your design is wrong. You don't need to rely on state on Cloud Run instances and think to update it by push.

例如,您需要将状态存储在外部,Memorystore或Firestore上,并在每次请求时获取数据.

You need to store the state externally, on Memorystore or firestore, and to get the data at each request for example.

这篇关于Pubsub,推送到所有Cloud Run容器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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