简体   繁体   English

为什么使用 Gcloud Pub/Sub?

[英]Why Gcloud Pub/Sub is used?

Why Pub/Sub is used?为什么使用 Pub/Sub? Usecase: There is a http triggered "Cloud function" on which some Data is sent.用例:有一个 http 触发了“云功能”,在该功能上发送了一些数据。 This function after processing data, publishes Data to a Pub/Sub topic.此 function 处理数据后,将数据发布到 Pub/Sub 主题。

Then there is another Cloud function, which is triggered based on publishing to that Pub/sub topic.然后还有另一个 Cloud function,它是基于发布到该 Pub/sub 主题而触发的。 So, This Cloud function takes published data from pub/sub and inserts it to a BigQuery table.因此,This Cloud function 从 pub/sub 获取已发布的数据并将其插入到 BigQuery 表中。

So in this usecase why pub sub is used, why can't we just have one cloud function which takes data from http hit, and inserts it to BigQuery.所以在这个用例中为什么要使用 pub sub,为什么我们不能只有一个云 function 从 http 中获取数据,并将其插入 BigQuery。 What cam be the design thought given for choosing pub/sub here?在这里选择 pub/sub 的设计思路是什么?

Also generally why Pub/sub architecture is used?通常为什么使用 Pub/sub 架构?

There could be several reasons to use Cloud Pub/Sub in this architecture.在此架构中使用 Cloud Pub/Sub 可能有多种原因。 One reason would be if there is any fan out or plans to fan out, where the published data ends up not only in BigQuery, but in some other place.一个原因是,如果有任何扇出或计划扇出,发布的数据不仅会出现在 BigQuery 中,还会出现在其他地方。 Without Pub/Sub, the http-triggered Cloud Function would have to know about all interested receivers of the data and send it to each one of them.如果没有 Pub/Sub,http 触发的 Cloud Function 将必须了解所有感兴趣的数据接收者并将其发送给每个接收者。 With Pub/Sub, any additional service that was interested in the incoming data could create a separate subscription on the data and consume it independently of BigQuery.使用 Pub/Sub,任何对传入数据感兴趣的附加服务都可以对数据创建单独的订阅,并独立于 BigQuery 使用它。

Another reason would be to be able to batch data inserts into BigQuery without increasing latency on the http requests to the initial Cloud Function.另一个原因是能够将数据批量插入 BigQuery,而不会增加对初始 Cloud Function 的 http 请求的延迟。 This may be done for efficiency or for doing some kind of cross-event pre-processing on the data coming in. By using Pub/Sub, the first Cloud Function can respond to the request as soon as the publish to Cloud Pub/Sub succeeds, not having to wait for any other requests, and can be sure that the request will ultimately be processed.这可能是为了提高效率或对传入的数据进行某种跨事件预处理。通过使用 Pub/Sub,第一个 Cloud Function 可以在发布到 Cloud Pub/Sub 成功后立即响应请求,不必等待任何其他请求,并且可以确定该请求最终会得到处理。

In the absence of these two either now or in the future, it may make sense to write to BigQuery directly.在现在或将来没有这两个的情况下,直接写入 BigQuery 可能是有意义的。

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

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