Google Pub/Sub - No event data found from local function after published message to topic

1k Views Asked by At

I'm using the Functions Framework with Python alongside Google Cloud Pub/Sub Emulator. I'm having issues with an event triggered from a published message to a topic, where there's no event data found for the function. See more details below.

  • Start Pub/Sub Emulator under http://localhost:8085 and project_id is local-test.
  • Spin up function with signature-type: http under http://localhost:8006.
  • Given a background cloud function with signature-type: event:
  1. Topic is created as test-topic
  2. Function is spinned up under http://localhost:8007.
  3. Create push subscription test-subscription for test-topic for endpoint: http://localhost:8007

When I publish a message to test-topic from http://localhost:8006 via POST request in Postman, I get back a 200 response to confirm the message was published successfully. The function representing http://localhost:8007 gets executed as an event as shown in the logs from the functions-framework. However, there's no actual data for event when debugging the triggered function.

Has anyone encountered this? Any ideas/suggestions on this?
Perhaps, this is true? #23 Functions Framework does not work with the Pub/Sub emulator

Modules Installed

  • functions-framework==2.1.1
  • google-cloud-pubsub==2.2.0

python version

  • 3.8.8
1

There are 1 best solutions below

0
On BEST ANSWER

I'll close this post, since the issue is an actual bug that was reported last year.

Update: As a workaround until this bug is fixed, I copied the code below locally to functions_framework/__init__.py within view_func nested function, inside _event_view_func_wrapper function.

if 'message' in event_data:
    if 'data' not in event_data:
        message = event_data['message']
        event_data['data'] = {
            'data': message.get('data'),
            'attributes': message.get('attributes')
        }