Google Cloud Pub/Sup API:StreamingPull 几乎 100% 错误但仍然有效?

Google Cloud Pub/Sup API: Almost 100% Errors on StreamingPull but still works?

我刚刚开始使用 Google 云 Pub/Sub 作为基于事件的架构的一部分。当我刚刚检查 API 仪表板并看到我在 StreamingPull 方法上几乎有 100% 的错误时,我有些惊讶。然而,似乎一切都在按预期进行。

我在 node.js 应用程序(在服务器上 运行ning)中使用一个侦听器,在本地 运行 python 脚本中使用另一个侦听器(目前正在开发中,现在 运行。

我的 node.js 实例化如下所示:

const { PubSub } = require("@google-cloud/pubsub");

client = new PubSub({
    projectId: conf.GOOGLE_PROJECT_ID,
    credentials: {
        client_email: conf.GOOGLE_CLIENT_EMAIL,
        private_key: conf.GOOGLE_CLIENT_PRIVATE_KEY
    },
});

const subscription = client.subscription(subscriptionName);

subscription.on("message", (message) => {
    console.log(`Received message ${message.id}:`);
    console.log(JSON.parse(message.data));
    const parsedMessage = JSON.parse(message.data).message;

    if (parsedMessage) {
      ... do things ...
    }
    message.ack()
});

const errorHandler = function (error) {
    console.error(`ERROR: ${error}`);
    throw error;
};

subscription.on("error", errorHandler);

任何人都可以阐明这一点吗?

这是预期的 explained in the documentation:

"StreamingPull streams are always terminated with a non-OK status. Note that, unlike in regular RPCs, the status here is simply an indication that the stream has been broken, not that requests are failing. Therefore, while the StreamingPull API may have a seemingly surprising 100% error rate, this is by design."