【问题标题】:Ensure PubSub batch requests are sent in Google Cloud Run Node App确保 PubSub 批处理请求在 Google Cloud Run Node App 中发送
【发布时间】:2020-03-09 18:21:36
【问题描述】:

我有一个 NodeJS 服务器在 Google Cloud Run 的容器中运行。它将消息发布到 PubSub。

// during handling a request, 
const topic = pubsub.topic(topicName, {
    batching: {
        maxMessages: 1000,
        maxMilliseconds: 1000,
    },
});

// publish some messages
someArray.forEach((item) => {
    topic.publishJSON(item);
});

假设 someArray.length 小于 maxMessages。 如果节点在 maxMilliseconds 过去之前发送响应会发生什么?消息是否发送? Google Cloud Run 是否会在 http 响应时终止容器,或者它是否知道 PubSub 库已设置超时?

【问题讨论】:

    标签: node.js google-cloud-pubsub google-cloud-run


    【解决方案1】:

    Cloud Run 不会立即杀死容器,而是在处理请求后limits 访问 CPU。正如文档建议的那样,完成请求处理中的所有异步任务。像the example 一样尝试异步/等待。

    【讨论】:

      猜你喜欢
      • 2018-08-10
      • 2019-12-20
      • 2021-11-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-02-19
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多