-
Notifications
You must be signed in to change notification settings - Fork 63
Cannot unmarshal CloudEvent from pubsub push #26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
My function is: package function
import (
"context"
"fmt"
cloudevents "github.com/cloudevents/sdk-go/v2"
)
func CloudEventsFunction(ctx context.Context, e cloudevents.Event) error {
fmt.Println("RECEIVED")
return nil
} and it is never called. This is the library used to serialise the message: https://github.com/cloudevents/sdk-go/blob/master/v2/protocol/pubsub/message.go |
Doing more digging, it appears that isStructuredCloudEvent expects cloud event data as headers, but they are instead present in the message attributes. As a result, the framework attempts to parse the message as a legacyEvent. But, the fields in attributes are The headers for the invocation are:
I also tried sending a message with specversion 0.3, to see if it was serialised differently, but the same issue happens. I also hacked the pubsub message writer in the sending library to not prefix the attributes: But that didn't work either:
|
Well I guess here's the problem maybe? Functions framework uses the v1 of the cloud events.
|
Hi @majelbstoat, a Pub/Sub push event does not deliver the event in CloudEvent format. It's not a CloudEvent, it's a custom JSON event. As a result, you're seeing the unmarshal issue Can you get this sample in the official docs to work? We're currently adding CloudEvent support to this repo. |
I ended up using the cloudevents SDK directly and creating a custom format to decode it, not entirely unlike the docs.
Great! |
Sending a simple cloudevent message results in the following error:
Formatted event data for clarity:
The text was updated successfully, but these errors were encountered: