【问题标题】:Google Cloud Pub/Sup API: Almost 100% Errors on StreamingPull but still works?Google Cloud Pub/Sup API:StreamingPull 几乎 100% 错误但仍然有效?
【发布时间】:2020-05-28 22:09:19
【问题描述】:

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

我在 node.js 应用程序(在服务器上运行)中使用了一个侦听器,在本地运行的 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);

有人能解释一下吗?

【问题讨论】:

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


    【解决方案1】:

    这是意料之中的explained in the documentation:

    "StreamingPull 流总是以非 OK 状态终止。请注意,与常规 RPC 不同,这里的状态只是表明流已被破坏,而不是请求失败。因此,当 StreamingPull API可能有一个看似令人惊讶的 100% 错误率,这是设计使然。”

    【讨论】:

      猜你喜欢
      • 2015-06-21
      • 2015-09-10
      • 1970-01-01
      • 1970-01-01
      • 2013-10-27
      • 1970-01-01
      • 2017-06-17
      • 2016-12-29
      • 1970-01-01
      相关资源
      最近更新 更多