Functions-framework (emulator) subscribing to Pub/Sub emulator

435 views
Skip to first unread message

Michal Moravík

unread,
May 12, 2021, 11:30:35 AM5/12/21
to Google Cloud Developers
Hey! I want to trigger a cloud function by using a Pub/Sub subscription. I want to do this locally first, so I chose functions-framework and Pub/Sub emulator. My problem is that the function is never triggered when using --signature-type=event. I don't know if the combination of these two locally run services is even possible. I made a StackOverflow question where I explain more. Any help would be appreciated.  

Alexis (Google Cloud Support)

unread,
May 12, 2021, 3:05:57 PM5/12/21
to Google Cloud Developers

Hi,

When I go to your stackoverflow link and read all the steps you took, I do not see the step for starting the emulator. This may explain why the function is not being triggered. Please follow all the steps here[1] and let us know what happens after that.

Michal Moravík

unread,
May 13, 2021, 1:15:35 PM5/13/21
to Google Cloud Developers
Hey!

Thanks for your reply. Actually, the emulator is started automatically since it is dockerized. I am trying to figure out what would be the best solution for triggering cloud function (functions-framework) from Pub/Sub dockerized emulator. So far I have found this and yesterday Samarth replied to my StackOverflow question with another example

I would prefer to use the Pub/Sub's pull method but this probably requires a local listener that could imitate GCP's behavior and listen to my Pub/Sub emulator regularly. Or maybe I can set up a push method that is described in the first link I attached, but this would not be optimal with my production deployment which will, most likely, be the pull method.

I want to avoid having a push method for local development and a pull method for production because then it would create a mess. What do you think would be the best solution, please?

Thanks! :) 

Alexis (Google Cloud Support)

unread,
May 14, 2021, 2:02:20 PM5/14/21
to Google Cloud Developers
Hi,

I would first start by doing it exactly as the documentation says. And then start isolating the problem. You have too many systems interacting with each other that could be causing this issue. And the --signature-type=event that you removed bypasses some of the emulation mechanism. This would explain why it kind of worked.

For example, it says here[1] "The emulator listens on port 8085 on your localhost (127.0.0.1) by default". When I look at your docker compose, I do not see this port. In addition, how are you starting the emulator? Unless a command is included in the image, this[1] documentation says to run "gcloud beta emulators pubsub start". Unless there's something else I'm not seeing. Also, note this[2] step that says how to create a local push endpoint for testing push subscriptions.

My recommendation is to try isolating between a config issue or local system issue. Separate those two first by finding-out if the official configuration works. Otherwise, it will be very hard for others to perceive a potential local issue. As someone stated in the stackoverflow, the function is not being triggered. This is a communication issue and related to everything else before that.

Let me know if there's something I've missed

Reply all
Reply to author
Forward
0 new messages