Firebase PubSub 模拟器不接收消息
Firebase PubSub Emulator not recieving messages
我正在尝试获取 firebase 模拟器,以使用 pubsub 发布来触发云功能。
基本设置在云功能之外工作。
尝试连接云功能时,没有任何消息出现。
我有一种感觉,我做了一些根本性的错误。
发布代码:
import { PubSub, Topic } from '@google-cloud/pubsub';
const topicName = 'MyTopic';
const [taskTopic] = await pubsub.createTopic(topicName);
await this.taskTopic.publish(Buffer.from(msg));
“手册”订阅:作品
[subscription] = await this.renderTaskTopic.createSubscription(subscriptionName);
subscription.on('message', (message) => {
console.log('Received message:', message.data.toString());
process.exit(0);
});
使用云函数订阅:永远不会在模拟器中调用
export const subscribeToRenderTask = functions.pubsub.topic(topicName)
.onPublish(async (message: functions.pubsub.Message) => {
console.log('subscribeToRenderTask', message.data);
}
emulator 设置似乎不错
functions: The Firebase Authentication emulator is not running, so calls to Firebase Authentication will affect production.
✔ functions[convert]: http function initialized (http://0.0.0.0:5001/puredio-development/europe-west3/convert).
✔ functions[subscribeToRenderTask]: pubsub function initialized.
┌─────────────────────────────────────────────────────────────┐
│ ✔ All emulators ready! It is now safe to connect your app. │
│ i View Emulator UI at http://0.0.0.0:8081 │
└─────────────────────────────────────────────────────────────┘
┌───────────┬────────────────┬───────────────────────────────┐
│ Emulator │ Host:Port │ View in Emulator UI │
├───────────┼────────────────┼───────────────────────────────┤
│ Functions │ 0.0.0.0:5001 │ http://0.0.0.0:8081/functions │
├───────────┼────────────────┼───────────────────────────────┤
│ Firestore │ 0.0.0.0:8080 │ http://0.0.0.0:8081/firestore │
├───────────┼────────────────┼───────────────────────────────┤
│ Pub/Sub │ 127.0.0.1:8085 │ n/a │
└───────────┴────────────────┴───────────────────────────────┘
Emulator Hub running at 127.0.0.1:4400
Other reserved ports: 4500
RTFM:我需要设置以下环境变量,这样我的测试才能真正找到 pub sub 模拟器
export PUBSUB_EMULATOR_HOST = 'localhost:8085'
export PUBSUB_PROJECT_ID = 'my-project'
我正在尝试获取 firebase 模拟器,以使用 pubsub 发布来触发云功能。 基本设置在云功能之外工作。 尝试连接云功能时,没有任何消息出现。
我有一种感觉,我做了一些根本性的错误。
发布代码:
import { PubSub, Topic } from '@google-cloud/pubsub';
const topicName = 'MyTopic';
const [taskTopic] = await pubsub.createTopic(topicName);
await this.taskTopic.publish(Buffer.from(msg));
“手册”订阅:作品
[subscription] = await this.renderTaskTopic.createSubscription(subscriptionName);
subscription.on('message', (message) => {
console.log('Received message:', message.data.toString());
process.exit(0);
});
使用云函数订阅:永远不会在模拟器中调用
export const subscribeToRenderTask = functions.pubsub.topic(topicName)
.onPublish(async (message: functions.pubsub.Message) => {
console.log('subscribeToRenderTask', message.data);
}
emulator 设置似乎不错
functions: The Firebase Authentication emulator is not running, so calls to Firebase Authentication will affect production.
✔ functions[convert]: http function initialized (http://0.0.0.0:5001/puredio-development/europe-west3/convert).
✔ functions[subscribeToRenderTask]: pubsub function initialized.
┌─────────────────────────────────────────────────────────────┐
│ ✔ All emulators ready! It is now safe to connect your app. │
│ i View Emulator UI at http://0.0.0.0:8081 │
└─────────────────────────────────────────────────────────────┘
┌───────────┬────────────────┬───────────────────────────────┐
│ Emulator │ Host:Port │ View in Emulator UI │
├───────────┼────────────────┼───────────────────────────────┤
│ Functions │ 0.0.0.0:5001 │ http://0.0.0.0:8081/functions │
├───────────┼────────────────┼───────────────────────────────┤
│ Firestore │ 0.0.0.0:8080 │ http://0.0.0.0:8081/firestore │
├───────────┼────────────────┼───────────────────────────────┤
│ Pub/Sub │ 127.0.0.1:8085 │ n/a │
└───────────┴────────────────┴───────────────────────────────┘
Emulator Hub running at 127.0.0.1:4400
Other reserved ports: 4500
RTFM:我需要设置以下环境变量,这样我的测试才能真正找到 pub sub 模拟器
export PUBSUB_EMULATOR_HOST = 'localhost:8085'
export PUBSUB_PROJECT_ID = 'my-project'