0
votes

This may deserve an issue against the Cloud Pub/Sub service. But so far the GCP support isn't really helpful so I am posting this issue here.

According to here, the Pubsub message should have a messageId property, whether it's from pull or push.

So I am trying to see what the message looks like: (event here is the pubsub message pushed to the cloud function)

exports.my_cloud_function = (event) => {
    logger.debug(`Event: ${util.inspect(event)}`);
}

What I expected:

{ '@type': 'type.googleapis.com/google.pubsub.v1.PubsubMessage', messageId:'111111111', publishTime: 'Oct 1st 2019, xxxx', attributes: { key1: 'value1', key2: 'value2' }, data: 'eLCJ=(some base 64)' }

What actually is:

{ '@type': 'type.googleapis.com/google.pubsub.v1.PubsubMessage', attributes: { key1: 'value1', key2: 'value2' }, data: 'eLCJ=(some base 64)' }
1
Edit your question and show how this message is generated. You say that Google is not helpful. Post the Issue Tracker details with your question so that I can look this up. - John Hanley
How is your message being published to the topic? - Kolban

1 Answers

3
votes

If I guess well, you are using a Cloud Function with an event trigger. And it's a common trap (I felt in it several times...).

So, in event format, the publishedTime and the messageId are in the context object and not in the event as describe here

In your function, add the context in param, and print it. It should work.

exports.my_cloud_function = (event,context) => {
    logger.debug(`Event: ${util.inspect(event)}`);
    logger.debug(`Context: ${util.inspect(context)}`);
}