首页 > 解决方案 > 如何在将消息发布到 Google Cloud Pub/Sub 时找出未找到的资源?

问题描述

我对谷歌云很陌生。我想从我的 nodejs 应用程序完成消息发布到 Google Cloud Pub/Sub 服务。但是,我在发布消息时收到以下错误:

Received error while publishing: Error: 5 NOT_FOUND: Resource not found (resource=193060).

我想不通resource=193060 。什么是 193060?

这是我的server.js

const express = require('express');
const app = express();
const bodyParser = require("body-parser");
const {PubSub} = require('@google-cloud/pubsub');

// parse application/json
app.use(bodyParser.json({limit: '10mb'}))

// Creates a client; cache this for further use
const pubSubClient = new PubSub();
const topicName = 'projects/codeway-312008/topics/codeway-log';
const data2 = JSON.stringify({
    type: 'event',
    app_id: 'com.codeway.test',
    session_id: 'vIfEMi9kJW',
    event_name: 'about',
    event_time: 1598196427881,
    page: 'settings',
    country: 'US',
    region: 'New Jersey',
    city: 'Newark',
    user_id: '9t0lrnYLQr'
});


async function publishMessage() {
    // Publishes the message as a string, e.g. "Hello, world!" or JSON.stringify(someObject)
    const dataBuffer = Buffer.from(data2);

    try {
        const messageId = await pubSubClient.topic(topicName).publish(dataBuffer);
        console.log(`Message ${messageId} published.`);
    } catch (error) {
        console.error(`Received error while publishing: ${error}`);
        process.exitCode = 1;
    }
}


publishMessage();
 

我的主题:

在此处输入图像描述

标签: node.jsgoogle-cloud-platformgoogle-cloud-pubsub

解决方案


看起来缺少的资源是与主题关联的架构。它可能在创建主题后被删除。需要清理错误消息以使其更清晰,因此 Cloud Pub/Sub 团队一定会这样做。


推荐阅读