简体   繁体   中英

Firebase Emulator: using PubSub in Functions

I am trying to run my Firebase functions locally through the emulator. I have built a architecture where chains of processes are invoked by PubSub events. When trying to invoke these events, the emulator logs give me this:

Sorry, we cannot connect to Cloud Services without a project ID. You may specify one with an environment variable named "GOOGLE_CLOUD_PROJECT".

I am running the emulators with --project {projectID} . Also I am constructing my PubSub events like this:

const pubsub = new PubSub({ projectId: getRealtimeDatabase().app.options.projectId })

I am using package "@google-cloud/pubsub": "^0.22.2" , and I am importing PubSub like import { PubSub } from '@google-cloud/pubsub';

What do I have to do to make PubSub invoke new events? Thanks!

Turned out getRealtimeDatabase().app.options.projectId was undefined. I retrieved my projectId elsewhere. With the correct projectId, the code above works.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM