Firebase PubSub仿真器未收到消息 [英] Firebase PubSub Emulator not recieving messages

查看:133
本文介绍了Firebase PubSub仿真器未收到消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试获取Firebase模拟器,以使用pubsub发布触发云功能.基本设置在云功能之外起作用.尝试连接云功能时,不会出现任何消​​息.

I'm trying to get the firebase emulator, to trigger cloud functions using pubsub publishing. The basic setup works outside of the cloud functions. When trying to connect the cloud function, no message ever appears.

我有种感觉,就是我做错了什么.

I have the feeling, that I doing something fundamentally wrong.

发布代码:

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);
 });

使用云功能进行订阅:永远不会在模拟器中被调用

Subscription using cloud function: never gets called in the emulator


export const subscribeToRenderTask = functions.pubsub.topic(topicName)
    .onPublish(async (message: functions.pubsub.Message) => {
        console.log('subscribeToRenderTask', message.data);
     }

Emalutor设置似乎很好

The emalutor setup seems fine

 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子模拟器

RTFM: I needed to set the following env vars so that my tests could actually find the pub sub emulator

export PUBSUB_EMULATOR_HOST = 'localhost:8085'
export PUBSUB_PROJECT_ID = 'my-project'

这篇关于Firebase PubSub仿真器未收到消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆