【发布时间】:2021-06-20 06:43:56
【问题描述】:
我正在尝试在本地使用 pubsub 运行 firebase 函数。
已使用firebase init emulators 配置了模拟器。
firebase emulators:start --only pubsub 工作正常,我可以看到日志:
┌──────────┬────────────────┐
│ Emulator │ Host:Port │
├──────────┼────────────────┤
│ Pub/Sub │ localhost:8085 │
└──────────┴────────────────┘
firebase.json 中的 pubsub 模拟器配置:
"pubsub": {
"host": "localhost",
"port": 8085
},
一个 pubsub 处理函数被导出:
exports.testPubsub = functions.pubsub.topic("test-pubsub").onPublish(async (message) => {
console.log(`test event received by pubsub handler: ${message.json}`);
});
我使用以下方式运行 firebase 函数:firebase serve --only functions
此行出现在控制台输出中:
functions[pubsub-testPubsub]: function ignored because the pubsub emulator does not exist or is not running. {"metadata":{"emulator":{"name":"functions"},"message":"function ignored because the pubsub emulator does not exist or is not running."}}
这意味着找到了函数,但由于某种原因,firebase 无法连接到 pubsub 模拟器,尽管进行了所有配置。
这是一个问题: 如何在本地机器上测试 pubsub 和 firebase 功能?
【问题讨论】:
标签: firebase google-cloud-pubsub