-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Migration guide for EventGrid #15731
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
Merged
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| # Guide for migrating to azure-eventgrid v2.0 from azure-eventgrid v1.3 | ||
|
|
||
| This guide is intended to assist in the migration to azure-eventgrid v2.0 from azure-eventgrid v1.3. It will focus on side-by-side comparisons for similar operations between the two packages. | ||
|
|
||
| Familiarity with the azure-eventgrid v1.3 package is assumed. For those new to the eventgrid client library for Python, please refer to the [README for azure-eventgrid v2.0](https://github.com/Azure/azure-sdk-for-python/blob/master/sdk/eventgrid/azure-eventgrid/README.md) rather than this guide. | ||
|
|
||
| ## Migration benefits | ||
|
|
||
| A natural question to ask when considering whether or not to adopt a new version or library is what the benefits of doing so would be. As Azure has matured and been embraced by a more diverse group of developers, we have been focused on learning the patterns and practices to best support developer productivity and to understand the gaps that the Python client libraries have. | ||
|
|
||
| There were several areas of consistent feedback expressed across the Azure client library ecosystem. One of the most important is that the client libraries for different Azure services have not had a consistent approach to organization, naming, and API structure. Additionally, many developers have felt that the learning curve was difficult, and the APIs did not offer a good, approachable, and consistent onboarding story for those learning Azure or exploring a specific Azure service. | ||
|
|
||
| To try and improve the development experience across Azure services, a set of uniform [design guidelines](https://azure.github.io/azure-sdk/general_introduction.html) was created for all languages to drive a consistent experience with established API patterns for all services. A set of [Azure SDK Design Guidelines for Python](https://azure.github.io/azure-sdk/python_introduction.html#design-principles) was also introduced to ensure that Python clients have a natural and idiomatic feel with respect to the Python ecosystem. Further details are available in the guidelines for those interested. | ||
yunhaoling marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ### Cross Service SDK improvements | ||
|
|
||
| The modern Event Grid client library also provides the ability to share in some of the cross-service improvements made to the Azure development experience, such as | ||
| - a unified logging and diagnostics pipeline offering a common view of the activities across each of the client libraries | ||
yunhaoling marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| ## Important changes | ||
|
|
||
| ### Support for Cloud Events | ||
|
|
||
| The v2.x major version comes with support for [CloudEvents](https://github.com/cloudevents/spec). Now the cloud native Cloud Events can be directly published using the `CloudEvent` constructor or a as a dictionary as follows: | ||
yunhaoling marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ```Python | ||
| from azure.eventgrid import CloudEvent | ||
|
|
||
| cloud_event = CloudEvent( | ||
| type="Contoso.Items.ItemReceived", | ||
| source="/contoso/items", | ||
| data={ | ||
| "itemSku": "Contoso Item SKU #1" | ||
| }, | ||
| subject="Door1" | ||
| ) | ||
|
|
||
| # as a dictionary | ||
|
|
||
| cloud_event = { | ||
| "type":"a0517898-9fa4-4e70-b4a3-afda1dd68672", | ||
| "source":"/subscriptions/{subscription-id}/resourceGroups/{resource-group}/providers/Microsoft.Storage/storageAccounts/{storage-account}", | ||
| "data": {"hello": "world"}, | ||
| "subject": "Door1" | ||
| } | ||
| ``` | ||
|
|
||
| ### Client constructors | ||
|
|
||
| * The `EventGridClient` in the v1.3 has been replaced with `EventGridPublisherClient`. | ||
|
|
||
| | In v1.3 | Equivalent in v2.0 | Sample | | ||
| |---|---|---| | ||
| |`EventGridClient(credentials)`|`EventGridPublisherClient(topic_hostname, credential)`|[Sample for client construction](https://github.com/Azure/azure-sdk-for-python/blob/master/sdk/eventgrid/azure-eventgrid/samples/champion_scenarios/cs5_publish_events_using_cloud_events_1.0_schema.py)| | ||
|
|
||
| * Additionally, we now have an `EventGridConsumer` that should be used to deserialize the events. | ||
|
|
||
| ```Python | ||
| from azure.eventgrid import EventGridConsumer | ||
|
|
||
| eg_consumer = EventGridConsumer() | ||
yunhaoling marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ``` | ||
|
|
||
| ### Publishing Events | ||
|
|
||
| The `publish_events` API is replaced with `send` in v2.0. Additionally, `send` API accepts `CloudEvent`, `CustomEvent` along with `EventGridEvent` | ||
|
|
||
| | In v1.3 | Equivalent in v2.0 | Sample | | ||
| |---|---|---| | ||
| |`EventGridClient(credentials).publish_events(topic_hostname, events)`|`EventGridPublisherClient(topic_hostname, credential).send(events)`|[Sample for client construction](https://github.com/Azure/azure-sdk-for-python/blob/master/sdk/eventgrid/azure-eventgrid/samples/champion_scenarios/cs5_publish_events_using_cloud_events_1.0_schema.py)| | ||
|
|
||
| ### Consuming Events | ||
yunhaoling marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| In v2.0, `EventGridConsumer` can be used to decode both Cloud Events and EventGrid Events. | ||
|
|
||
| ```Python | ||
| EventGridConsumer().decode_cloud_event(cloud_event) | ||
|
|
||
| EventGridConsumer().decode_eventgrid_event(eventgrid_event) | ||
yunhaoling marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ``` | ||
|
|
||
| ## Additional samples | ||
|
|
||
| More examples can be found at [here](https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/eventgrid/azure-eventgrid/samples) | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.