确保 PubSub 批处理请求在 Google Cloud 运行 Node App 中发送
Ensure PubSub batch requests are sent in Google Cloud Run Node App
我在 Google 云 运行 的容器中有一个 NodeJS 服务器 运行。它将消息发布到 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 运行 是在收到 http 响应后终止容器,还是以某种方式知道 PubSub 库已设置超时?
Cloud 运行 不会立即终止容器,但它 limits its access to CPU after processing the request. As the documentation suggests finish all the asynchronous tasks within request handling. Try async/await like in the example。
我在 Google 云 运行 的容器中有一个 NodeJS 服务器 运行。它将消息发布到 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 运行 是在收到 http 响应后终止容器,还是以某种方式知道 PubSub 库已设置超时?
Cloud 运行 不会立即终止容器,但它 limits its access to CPU after processing the request. As the documentation suggests finish all the asynchronous tasks within request handling. Try async/await like in the example。