@@ -59,43 +59,58 @@ dotnet new gcf-event
59
59
```
60
60
61
61
That will create the same set of files as before, but the ` Function `
62
- class now implements ` ICloudEventFunction ` . This is a function that
63
- responds to [ CNCF Cloud Events] ( https://cloudevents.io/ ) . The procedure
64
- for running a Cloud Event Function is exactly the same as for an
65
- HTTP Function.
66
-
67
- ## Legacy Event Functions
68
-
69
- Google Cloud Functions support for events predates the CNCF Cloud
70
- Events initiative. "Legacy" event functions handle these events via
71
- the ` ILegacyEventFunction<T> ` type. The type parameter ` T `
72
- represents the payload type of the event. Any class type that can be
73
- deserialized via ` System.Text.Json ` can be used, but the Functions
74
- Framework for .NET comes with the following payload types built-in,
75
- all within the ` Google.Cloud.Functions.LegacyEvents ` namespace:
76
-
77
- - ` StorageObject ` for Google Cloud Storage events
78
- - ` FirestoreEvent ` for Cloud Firestore events
79
- - ` PubSubMessage ` for Cloud Pub/Sub messages
80
-
81
- See the Google Cloud Functions [ "Events and Triggers"
82
- documentation] ( https://cloud.google.com/functions/docs/concepts/events-triggers )
83
- for more information about the triggers available.
62
+ class now implements ` ICloudEventFunction<StorageObject> ` . This is a
63
+ function that responds to [ CNCF Cloud
64
+ Events] ( https://cloudevents.io/ ) , expecting data corresponding to a
65
+ Google Cloud Storage object. If you deploy the function with a
66
+ trigger of ` google.storage.object.finalize ` and then upload a new
67
+ object to Google Cloud Storage, the sample event will log the
68
+ details of the new event, including some properties of the storage
69
+ object.
70
+
71
+ The procedure for running a Cloud Event Function is exactly the same
72
+ as for an HTTP Function.
73
+
74
+ The type argument to the generic ` ICloudEventFunction<TData> ` interface
75
+ expresses the type of data your function expects within the
76
+ CloudEvent. This is deserialized using System.Text.Json
77
+ deserialization: you can specify any type, so long as
78
+ it can be deserialized appropriately from the Cloud Event data
79
+ attribute.
80
+
81
+ > ** Note:**
82
+ > Google Cloud Functions support for events predates the CNCF Cloud
83
+ > Events initiative. The types in the ` Google.Cloud.Functions.Framework.GcfEvents `
84
+ > namespace provide payloads for these events. The Functions Framework
85
+ > converts the Google Cloud Functions representation into a Cloud Event
86
+ > representation transparently, so as a developer you only need to
87
+ > handle Cloud Events.
88
+
89
+ ### Untyped Cloud Event Functions
90
+
91
+ If you are experimenting with Cloud Events and don't yet have a
92
+ payload data model you wish to commit to, or you want your function
93
+ to be able to handle * any* CloudEvent, you can implement the
94
+ non-generic ` ICloudEventFunction ` interface. Your function's method
95
+ will then just be passed a ` CloudEvent ` , with no separate data object.
84
96
85
97
After installing the template package described earlier, use the
86
- ` gcf-legacy -event ` template:
98
+ ` gcf-untyped -event ` template:
87
99
88
100
``` sh
89
- mkdir HelloLegacyEvents
90
- cd HelloLegacyEvents
91
- dotnet new gcf-legacy -event
101
+ mkdir HelloUntypedEvents
102
+ cd HelloUntypedEvents
103
+ dotnet new gcf-untyped -event
92
104
```
93
105
94
- This will create a legacy event function consuming Google Cloud
95
- Storage events. If you deploy the function with a trigger of
96
- ` google.storage.object.finalize ` and then upload a new object to
97
- Google Cloud Storage, the sample event will log the details of the
98
- new event, including some properties of the storage object.
106
+ This will create a function that simply logs the information about
107
+ any Cloud Event it receives.
108
+
109
+ > ** Note:**
110
+ > The automatic conversion of Google Cloud Functions events to
111
+ > Cloud Events only happens for typed Cloud Event functions. Untyped
112
+ > Cloud Event functions only succeed when the underlying HTTP request
113
+ > contains a Cloud Event.
99
114
100
115
## VB and F# support
101
116
0 commit comments