Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Generate CloudEvents in the PubSub Emulator (#3767)
Update PubSub Emulator to emit events in CloudEvent format given a trigger whose function signature is `cloudevent`. Previously, the Functions Emulator considered 2 types of functions - `https` and `background`. With the introduction of [CloudEvents](https://cloud.google.com/functions/docs/writing/cloudevents) in Google Cloud Functions, we now have 2 types of `background` functions - `legacy` vs `cloudevent`. For example: ```js /* Legacy Events */ exports.helloPubSub = functions.pubsub.topic('topic-name').onPublish((message) => { // ... }); /* CloudEvents */ exports.helloPubSub = functions.v2.pubsub.topic('topic-name').onPublish((cloudevent) => { const message = cloudevent.data.message; }); ``` To accommodate, we adopt concept of "function signature" introduced in Google Cloud Function's [Functions Framework](https://github.com/GoogleCloudPlatform/functions-framework-nodejs) to categorize each function trigger as one of `http`, `event`, or`cloudevent`. When registering a function trigger with the Pubsub emulator, the functions's signature type will be included in the registration request, and the Pubsub emulator will use the info to emit an event in the format expected by the underlying function trigger. We also make minor changes to the Functions Emulator to selectively massage the incoming events in-route to the function trigger. As an added bonus, we are now able to remove `triggerType` field in the `FunctionsRuntimeArg` as that info is now outdated and not needed when invoking an emulated function.
- Loading branch information