Skip to content

Commit fc99fde

Browse files
Update README to remove outdated references (#22945)
* Update README to remove outdated references * Fix
1 parent 5ddb8c1 commit fc99fde

File tree

3 files changed

+19
-24
lines changed

3 files changed

+19
-24
lines changed

sdk/eventgrid/Azure.Messaging.EventGrid/README.md

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ There are several different Azure services that act as [event handlers](https://
233233

234234
Note: if using Webhooks for event delivery of the *Event Grid schema*, Event Grid requires you to prove ownership of your Webhook endpoint before it starts delivering events to that endpoint. At the time of event subscription creation, Event Grid sends a subscription validation event to your endpoint, as seen below. Learn more about completing the handshake here: [Webhook event delivery](https://docs.microsoft.com/azure/event-grid/webhook-event-delivery). For the *CloudEvents schema*, the service validates the connection using the HTTP options method. Learn more here: [CloudEvents validation](https://github.com/cloudevents/spec/blob/v1.0/http-webhook.md#4-abuse-protection).
235235

236-
Once events are delivered to the event handler, parse the JSON payload into list of events.
236+
Once events are delivered to the event handler, we can deserialize the JSON payload into a list of events.
237237

238238
Using `EventGridEvent`:
239239
```C# Snippet:EGEventParseJson
@@ -247,19 +247,16 @@ var bytes = await httpContent.ReadAsByteArrayAsync();
247247
// Parse the JSON payload into a list of events
248248
CloudEvent[] cloudEvents = CloudEvent.ParseMany(new BinaryData(bytes));
249249
```
250-
From here, one can access the event data by deserializing to a specific type using `GetData<T>()`. Calling `GetData()` will either return the event data wrapped in `BinaryData`, which represents the serialized JSON event data as bytes.
251-
252-
Using `GetData<T>()`:
253-
254-
Below is an example calling `GetData<T>()` for CloudEvents. In order to deserialize to the correct type, the `EventType` property (`Type` for CloudEvents) helps distinguish between different events. Custom event data should be deserialized using the generic method `GetData<T>()`. There is also an overload for `GetData<T>()` that accepts a custom `ObjectSerializer` to deserialize the event data.
250+
#### Deserializing event data
251+
From here, one can access the event data by deserializing to a specific type by calling `ToObjectFromJson<T>()` on the `Data` property. In order to deserialize to the correct type, the `EventType` property (`Type` for CloudEvents) helps distinguish between different events. Custom event data should be deserialized using the generic method `ToObjectFromJson<T>()`. There is also an extension method `ToObject<T>()` that accepts a custom `ObjectSerializer` to deserialize the event data.
255252

256253
```C# Snippet:DeserializePayloadUsingGenericGetData
257254
foreach (CloudEvent cloudEvent in cloudEvents)
258255
{
259256
switch (cloudEvent.Type)
260257
{
261258
case "Contoso.Items.ItemReceived":
262-
// By default, GetData uses JsonObjectSerializer to deserialize the payload
259+
// By default, ToObjectFromJson<T> uses System.Text.Json to deserialize the payload
263260
ContosoItemReceivedEventData itemReceived = cloudEvent.Data.ToObjectFromJson<ContosoItemReceivedEventData>();
264261
Console.WriteLine(itemReceived.ItemSku);
265262
break;
@@ -269,7 +266,7 @@ foreach (CloudEvent cloudEvent in cloudEvents)
269266
Console.WriteLine(testPayload.Name);
270267
break;
271268
case SystemEventNames.StorageBlobDeleted:
272-
// Example for deserializing system events using GetData<T>
269+
// Example for deserializing system events using ToObjectFromJson<T>
273270
StorageBlobDeletedEventData blobDeleted = cloudEvent.Data.ToObjectFromJson<StorageBlobDeletedEventData>();
274271
Console.WriteLine(blobDeleted.BlobType);
275272
break;
@@ -281,7 +278,7 @@ Using `TryGetSystemEventData()`:
281278

282279
If expecting mostly system events, it may be cleaner to switch on `TryGetSystemEventData()` and use pattern matching to act on the individual events. If an event is not a system event, the method will return false and the out parameter will be null.
283280

284-
*As a caveat, if you are using a custom event type with an EventType value that later gets added as a system event by the service and SDK, the return value of `TryGetSystemEventData` would change from `false` to `true`. This could come up if you are pre-emptively creating your own custom events for events that are already being sent by the service, but have not yet been added to the SDK. In this case, it is better to use the generic `GetData<T>` method so that your code flow doesn't change automatically after upgrading (of course, you may still want to modify your code to consume the newly released system event model as opposed to your custom model).*
281+
*As a caveat, if you are using a custom event type with an EventType value that later gets added as a system event by the service and SDK, the return value of `TryGetSystemEventData` would change from `false` to `true`. This could come up if you are pre-emptively creating your own custom events for events that are already being sent by the service, but have not yet been added to the SDK. In this case, it is better to use the generic `ToObjectFromJson<T>` method on the `Data` property so that your code flow doesn't change automatically after upgrading (of course, you may still want to modify your code to consume the newly released system event model as opposed to your custom model).*
285282

286283
```C# Snippet:DeserializePayloadUsingAsSystemEventData
287284
foreach (EventGridEvent egEvent in egEvents)
@@ -329,8 +326,9 @@ foreach (EventGridEvent egEvent in egEvents)
329326
`SendEvents()` returns an HTTP response code from the service. A `RequestFailedException` is thrown as a service response for any unsuccessful requests. The exception contains information about what response code was returned from the service.
330327

331328
### Deserializing Event Data
332-
- If the event data is not valid JSON, a `JsonException` will be thrown during `Parse`.
333-
- An `InvalidOperationException` will be thrown during `GetData<T>()` if a custom serializer is passed into `GetData<T>()` with non-serialized event data (for example, if the event was created by the user and not created by parsing from JSON).
329+
- If the event data is not valid JSON, a `JsonException` will be thrown when calling `Parse` or `ParseMany`.
330+
- If the event schema does not correspond to the type being deserialized to (e.g. calling `CloudEvent.Parse` on an EventGridSchema event), an `ArgumentException` is thrown.
331+
- If `Parse` is called on data that contains multiple events, an `ArgumentException` is thrown. `ParseMany` should be used here instead.
334332

335333
### Setting up console logging
336334
You can also easily [enable console logging](https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/core/Azure.Core/samples/Diagnostics.md#logging) if you want to dig deeper into the requests you're making against the service.

sdk/eventgrid/Azure.Messaging.EventGrid/samples/Sample3_ParseAndDeserializeEvents.md

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Handling events will be different based on which schema the event was delivered
99
- Deserialize the event data. Given an `EventGridEvent` or `CloudEvent`, the user can attempt to access the event payload, or data, by deserializing to a specific type. You can supply a custom serializer at this point to correctly decode the data.
1010

1111
## Parse Events from JSON payload
12-
Once events are delivered to the event handler, parse the JSON payload into list of events.
12+
Once events are delivered to the event handler, we can deserialize the JSON payload into a list of events.
1313

1414
Using `EventGridEvent`:
1515
```C# Snippet:EGEventParseJson
@@ -23,19 +23,16 @@ var bytes = await httpContent.ReadAsByteArrayAsync();
2323
// Parse the JSON payload into a list of events
2424
CloudEvent[] cloudEvents = CloudEvent.ParseMany(new BinaryData(bytes));
2525
```
26-
27-
## Deserialize Event Data
28-
From here, one can access the event data by deserializing to a specific type using `GetData<T>()` and passing in a custom serializer if necessary. Calling `GetData()` will either return a deserialized system event (an event generated by an Azure service), or the event data wrapped in `BinaryData`, which represents the serialized JSON event data as bytes.
29-
### Using `GetData<T>()`
30-
Below is an example calling `GetData<T>()` for CloudEvents. In order to deserialize to the correct type, the `EventType` property (`Type` for CloudEvents) helps distinguish between different events. Custom event data should be deserialized using the generic method `GetData<T>()`. There is also an overload for `GetData<T>()` that accepts a custom `ObjectSerializer` to deserialize the event data.
26+
### Deserializing event data
27+
From here, one can access the event data by deserializing to a specific type by calling `ToObjectFromJson<T>()` on the `Data` property. In order to deserialize to the correct type, the `EventType` property (`Type` for CloudEvents) helps distinguish between different events. Custom event data should be deserialized using the generic method `ToObjectFromJson<T>()`. There is also an extension method `ToObject<T>()` that accepts a custom `ObjectSerializer` to deserialize the event data.
3128

3229
```C# Snippet:DeserializePayloadUsingGenericGetData
3330
foreach (CloudEvent cloudEvent in cloudEvents)
3431
{
3532
switch (cloudEvent.Type)
3633
{
3734
case "Contoso.Items.ItemReceived":
38-
// By default, GetData uses JsonObjectSerializer to deserialize the payload
35+
// By default, ToObjectFromJson<T> uses System.Text.Json to deserialize the payload
3936
ContosoItemReceivedEventData itemReceived = cloudEvent.Data.ToObjectFromJson<ContosoItemReceivedEventData>();
4037
Console.WriteLine(itemReceived.ItemSku);
4138
break;
@@ -45,18 +42,18 @@ foreach (CloudEvent cloudEvent in cloudEvents)
4542
Console.WriteLine(testPayload.Name);
4643
break;
4744
case SystemEventNames.StorageBlobDeleted:
48-
// Example for deserializing system events using GetData<T>
45+
// Example for deserializing system events using ToObjectFromJson<T>
4946
StorageBlobDeletedEventData blobDeleted = cloudEvent.Data.ToObjectFromJson<StorageBlobDeletedEventData>();
5047
Console.WriteLine(blobDeleted.BlobType);
5148
break;
5249
}
5350
}
5451
```
5552

56-
### Using `TryGetSystemEventData()`
57-
If expecting mostly system events, it may be cleaner to switch on `TryGetSystemEventData()` and use pattern matching to act on the individual events. If an event is not a system event, the method will return false and the out parameter will be null.
53+
Using `TryGetSystemEventData()`:
54+
If expecting mostly system events, it may be cleaner to switch on `TryGetSystemEventData()` and use pattern matching to act on the individual events. If an event is not a system event, the method will return false and the out parameter will be null.
5855

59-
*As a caveat, if you are using a custom event type with an EventType value that later gets added as a system event by the service and SDK, the return value of `TryGetSystemEventData` would change from `false` to `true`. This could come up if you are pre-emptively creating your own custom events for events that are already being sent by the service, but have not yet been added to the SDK. In this case, it is better to use the generic `GetData<T>` method so that your code flow doesn't change automatically after upgrading (of course, you may still want to modify your code to consume the newly released system event model as opposed to your custom model).*
56+
*As a caveat, if you are using a custom event type with an EventType value that later gets added as a system event by the service and SDK, the return value of `TryGetSystemEventData` would change from `false` to `true`. This could come up if you are pre-emptively creating your own custom events for events that are already being sent by the service, but have not yet been added to the SDK. In this case, it is better to use the generic `ToObjectFromJson<T>` method on the `Data` property so that your code flow doesn't change automatically after upgrading (of course, you may still want to modify your code to consume the newly released system event model as opposed to your custom model).*
6057

6158
```C# Snippet:DeserializePayloadUsingAsSystemEventData
6259
foreach (EventGridEvent egEvent in egEvents)

sdk/eventgrid/Azure.Messaging.EventGrid/tests/Samples/Sample2_ParseAndDeserializeEvents.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ public async Task GenericReceiveAndDeserializeEventGridEvents()
9696
switch (cloudEvent.Type)
9797
{
9898
case "Contoso.Items.ItemReceived":
99-
// By default, GetData uses JsonObjectSerializer to deserialize the payload
99+
// By default, ToObjectFromJson<T> uses System.Text.Json to deserialize the payload
100100
ContosoItemReceivedEventData itemReceived = cloudEvent.Data.ToObjectFromJson<ContosoItemReceivedEventData>();
101101
Console.WriteLine(itemReceived.ItemSku);
102102
break;
@@ -106,7 +106,7 @@ public async Task GenericReceiveAndDeserializeEventGridEvents()
106106
Console.WriteLine(testPayload.Name);
107107
break;
108108
case SystemEventNames.StorageBlobDeleted:
109-
// Example for deserializing system events using GetData<T>
109+
// Example for deserializing system events using ToObjectFromJson<T>
110110
StorageBlobDeletedEventData blobDeleted = cloudEvent.Data.ToObjectFromJson<StorageBlobDeletedEventData>();
111111
Console.WriteLine(blobDeleted.BlobType);
112112
break;

0 commit comments

Comments
 (0)