Node.js 确保在Google Cloud Run Node应用程序中发送PubSub批处理请求

Node.js 确保在Google Cloud Run Node应用程序中发送PubSub批处理请求,node.js,google-cloud-pubsub,google-cloud-run,Node.js,Google Cloud Pubsub,Google Cloud Run,我有一个NodeJS服务器在googlecloudrun的容器中运行。它将消息发布到PubSub // during handling a request, const topic = pubsub.topic(topicName, { batching: { maxMessages: 1000, maxMilliseconds: 1000, }, }); // publish some messages someArray.forEach((

我有一个NodeJS服务器在googlecloudrun的容器中运行。它将消息发布到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。
如果节点在MaxMillimes之前发送响应,会发生什么情况?消息是否已发送?Google Cloud Run是否会在http响应时终止容器,或者它是否知道PubSub库已设置超时?

Cloud Run不会立即终止容器,但会在处理请求后终止对CPU的访问。正如文档所建议的,完成请求处理中的所有异步任务。像中一样尝试异步/等待。

云运行不会立即终止容器,但会在处理请求后终止对CPU的访问。正如文档所建议的,完成请求处理中的所有异步任务。像中一样尝试异步/等待