Background function POJO missing `timestamp` and `attributes`
I think the Background Function example in the docs is not quite correct: https://github.com/GoogleCloudPlatform/functions-framework-java#writing-a-typed-background-function
It doesn't seem like messageId, attributes, or publishTime gets populated in that message object when the background function is invoked:
public static class PubSubMessage {
public String data;
public Map<String, String> attributes;
public String messageId;
public String publishTime;
}
Any updates on this?
Hello! I just confirmed that calling the Background function does populate those fields. This is the sample PubSub payload I sent:
curl localhost:8080 -X POST -H "Content-Type: application/json" -d '{ "context": { "eventId":"1144231683168617", "timestamp":"2020-05-06T07:33:34.556Z", "eventType":"google.pubsub.topic.publish", "resource":{ "service":"pubsub.googleapis.com", "name":"projects/sample-project/topics/gcf-test", "type":"type.googleapis.com/google.pubsub.v1.PubsubMessage" } }, "data": { "@type": "type.googleapis.com/google.pubsub.v1.PubsubMessage", "attributes": { "attr1":"attr1-value" }, "data": "d29ybGQ=", "messageId": "2070443601311540", "publishTime": "2021-02-26T19:13:55.749Z" } }'
Here is the reference to the v1 pubsub message example in Json format: https://cloud.google.com/pubsub/docs/reference/rest/v1/PubsubMessage
And more examples of Pubsub here: https://cloud.google.com/eventarc/docs/workflows/cloudevents#common-events