Skip to content
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

Updating README and Samples for Event Grid #14568

Merged
merged 33 commits into from
Sep 2, 2020
Merged
Changes from 1 commit
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
fe79722
Updating README
Aug 25, 2020
8097e25
Updated README
Aug 25, 2020
44eff5c
More updates to README and samples
Aug 25, 2020
1e8fc61
Created samples README and sample files
Aug 26, 2020
c94050e
Update README.md
kerri-lee Aug 26, 2020
97b9927
Update README.md
kerri-lee Aug 26, 2020
a5f0ded
More samples
Aug 26, 2020
0584aaa
Merging changes
Aug 26, 2020
fc49727
Update README.md
kerri-lee Aug 26, 2020
d969ae4
Updating README
Aug 25, 2020
dfe28a0
Updated README
Aug 25, 2020
c2333ab
More updates to README and samples
Aug 25, 2020
51e013a
Created samples README and sample files
Aug 26, 2020
bf6c3c4
More samples
Aug 26, 2020
cc3a2f8
Update README.md
kerri-lee Aug 26, 2020
29c38e9
Update README.md
Aug 26, 2020
1e0f6a3
merging
Aug 26, 2020
53d3ded
Merging again?
Aug 26, 2020
3497de6
More updates to README and samples
Aug 25, 2020
5c2fca5
Created samples README and sample files
Aug 26, 2020
726e8f1
More samples
Aug 26, 2020
ce825f1
More merging
Aug 26, 2020
a7a49cd
Removing merge conflict
Aug 26, 2020
0cfe6fe
Updating samples to reflect new BinaryData api
Aug 26, 2020
dbf6cc1
Added async method
Aug 26, 2020
668f0bc
Updating samples
Aug 26, 2020
46e6828
Fixing broken links
Aug 26, 2020
5edc219
More changes to README and samples
Aug 27, 2020
c988efb
Small edits, updated system event types
Aug 31, 2020
9f22b80
Update README.md
kerri-lee Sep 1, 2020
b41759b
Edited sample to match readme snippet
Sep 1, 2020
08d0e3a
Update README.md
kerri-lee Sep 1, 2020
bd06c07
Updating session records
Sep 1, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 25 additions & 7 deletions sdk/eventgrid/Azure.Messaging.EventGrid/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Use the client library for Azure Event Grid to:
- Consume events that have been delivered to event handlers
- Generate SAS tokens to authenticate the client publishing events to Azure Event Grid topics

[Source code](https://github.com/Azure/azure-sdk-for-net/tree/master/sdk/eventgrid/Azure.Messaging.EventGrid) | [Package (NuGet)]() | [API reference documentation](https://azure.github.io/azure-sdk-for-net/eventgrid.html) | [Product documentation](https://docs.microsoft.com/en-us/azure/event-grid/)
[Source code](https://github.com/Azure/azure-sdk-for-net/tree/master/sdk/eventgrid/Azure.Messaging.EventGrid) | [Package (NuGet)]() | [API reference documentation](https://azure.github.io/azure-sdk-for-net/eventgrid.html) | [Product documentation](https://docs.microsoft.com/en-us/azure/event-grid/) | [Samples](samples)

## Getting started

Expand Down Expand Up @@ -70,7 +70,13 @@ For information about general Event Grid concepts: [Concepts in Azure Event Grid
A **publisher** sends events to the Event Grid service. Microsoft publishes events for several Azure services. You can publish events from your own application using the `EventGridPublisherClient`.

### Event schemas
An **event** is the smallest amount of information that fully describes something that happened in the system. Event Grid supports multiple schemas for encoding events. When a custom topic or domain is created, you specify the schema that will be used when publishing events. While you may configure your topic to use a custom schema, it is more common to use the already-defined [Event Grid schema](https://docs.microsoft.com/en-us/azure/event-grid/event-schema) or [CloudEvents 1.0 schema](https://docs.microsoft.com/en-us/azure/event-grid/cloud-event-schema). [CloudEvents](https://cloudevents.io/) is a Cloud Native Computing Foundation project which produces a specification for describing event data in a common way.
An **event** is the smallest amount of information that fully describes something that happened in the system. Event Grid supports multiple schemas for encoding events. When a custom topic or domain is created, you specify the schema that will be used when publishing events.

#### Event Grid schema
While you may configure your topic to use a custom schema, it is more common to use the already-defined Event Grid schema. See the specifications and requirements [here](https://docs.microsoft.com/en-us/azure/event-grid/event-schema).

#### CloudEvents v1.0 schema
Another option is to use the CloudEvents v1.0 schema. [CloudEvents](https://cloudevents.io/) is a Cloud Native Computing Foundation project which produces a specification for describing event data in a common way. The service summary of CloudEvents can be found [here](https://docs.microsoft.com/en-us/azure/event-grid/cloud-event-schema).

Regardless of what schema your topic or domain is configured to use, `EventGridPublisherClient` will be used to publish events to it.

Expand Down Expand Up @@ -207,24 +213,36 @@ foreach (CloudEvent cloudEvent in cloudEvents)
TestPayload testPayload = await cloudEvent.GetDataAsync<TestPayload>(myCustomSerializer);
Console.WriteLine(testPayload.Name);
break;
case "Microsoft.EventGrid.SubscriptionValidationEvent":
SubscriptionValidationEventData subscriptionValidated = cloudEvent.GetData<SubscriptionValidationEventData>();
Console.WriteLine(subscriptionValidated.ValidationCode);
case "Microsoft.Storage.BlobDeleted":
// Example for deserializing system events using GetData<T>
StorageBlobDeletedEventData blobDeleted = cloudEvent.GetData<StorageBlobDeletedEventData>();
Console.WriteLine(blobDeleted.BlobType);
break;
}
}
```

## Troubleshooting

#### Service Responses
### Service Responses
`SendEvents()` returns a 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.

#### Deserializing Event Data
### Deserializing Event Data
- An `InvalidCastException` will be thrown during `GetData<T>()` if the event data cannot be cast to the specified type.

- 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).

### Setting up console logging
The simplest way to see the logs is to enable the console logging.
To create an Azure SDK log listener that outputs messages to console use the AzureEventSourceListener.CreateConsoleLogger method.

```C#
// Setup a listener to monitor logged events.
using AzureEventSourceListener listener = AzureEventSourceListener.CreateConsoleLogger();
```

To learn more about other logging mechanisms see [Diagnostics Samples](https://github.com/Azure/azure-sdk-for-net/blob/master/sdk/core/Azure.Core/samples/Diagnostics.md).

## Next steps

View more samples here for common usages of the Event Grid client library: [Event Grid Samples](samples).
Expand Down