[英]Firebase functions won't see pubsub emulator running locally
I'm trying to run firebase functions with pubsub locally.我正在尝试在本地使用 pubsub 运行 firebase 函数。
Have configured emulators with firebase init emulators
.已使用
firebase init emulators
配置了仿真器。
firebase emulators:start --only pubsub
works properly, I can see log: firebase emulators:start --only pubsub
工作正常,我可以看到日志:
┌──────────┬────────────────┐
│ Emulator │ Host:Port │
├──────────┼────────────────┤
│ Pub/Sub │ localhost:8085 │
└──────────┴────────────────┘
pubsub emulator config in firebase.json: firebase.json 中的 pubsub 模拟器配置:
"pubsub": {
"host": "localhost",
"port": 8085
},
A pubsub handler function is exported:一个 pubsub 处理程序 function 被导出:
exports.testPubsub = functions.pubsub.topic("test-pubsub").onPublish(async (message) => {
console.log(`test event received by pubsub handler: ${message.json}`);
});
I run firebase functions with: firebase serve --only functions
我运行 firebase 功能:
firebase serve --only functions
This line appears in console output:此行出现在控制台 output 中:
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."}}
Which means function was found but for some reason firebase cannot connect to pubsub emulator, despite all the configs.这意味着找到了 function 但由于某种原因 firebase 无法连接到 pubsub 模拟器,尽管有所有配置。
And here is the question: How to test pubsub and firebase functions on local machine?这里是一个问题:如何在本地机器上测试 pubsub 和 firebase 功能?
After many hours of struggling I finally managed to make pubsub emulator work.经过数小时的努力,我终于设法使 pubsub 模拟器工作。
There is nothing about firebase serve
in firebase docs so I guess it's a deprecated command. firebase 文档中没有关于
firebase serve
的内容,所以我想这是一个不推荐使用的命令。 All I found was firebase emulators:start
.我发现的只是
firebase emulators:start
。
I followed instructions in To set up admin credentials for emulated functions: section.我按照为模拟功能设置管理员凭据:部分中的说明进行操作。 Created a key and downloaded json, exported variable in terminal and ran
firebase emulators:start
.创建一个密钥并下载 json,在终端中导出变量并运行
firebase emulators:start
。
That worked and I can see my log in outputs.那行得通,我可以看到我的登录输出。
Can't tell for sure what was the problem, but looks like you cannot firebase serve
and get in touch with emulator for some reason.不能确定是什么问题,但看起来你不能
firebase serve
并与模拟器取得联系。 You have to run all the emulators if you want them to work with each other.如果您希望它们相互协作,您必须运行所有模拟器。
Notes:笔记:
npm run build
npm run build
const pubsub = new PubSub({
projectId: "your-test-project",
});
const topic = pubsub.topic("test-pubsub");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.