node.js - 如何在将消息发布到 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();
我的主题:
解决方案
看起来缺少的资源是与主题关联的架构。它可能在创建主题后被删除。需要清理错误消息以使其更清晰,因此 Cloud Pub/Sub 团队一定会这样做。
推荐阅读
- html - Flexgrid PrimeNG - 生成空格/边距/填充
- reactjs - 反应:多个状态值改变了一个组合父级的值?
- javascript - 单击取消静音按钮后如何将音量设置为特定值?
- flutter - 为什么 FutureBuilder 不返回从 Sqlite 数据库查询的数据?
- javascript - 对象类型
- linkedin - 链接帖子中的自定义图像无法通过用于 LinkedIn 个人资料的 API
- c# - C# Linq JSON 嵌套数组的奇怪行为
- android - 无法解析符号 PreferenceFragmentCompat
- excel - 超链接点击运行功能两次并给出补丁错误
- javascript - 启动 Selenium IE11 WebDriver 或执行 JS 时 Python 操作卡住