Skip to content

Commit 1e453ab

Browse files
author
Rakshith Bhyravabhotla
authored
Migration guide for EventGrid (Azure#15731)
* initial commit * Update migration_guide.md * comments
1 parent 4c62441 commit 1e453ab

File tree

1 file changed

+96
-0
lines changed

1 file changed

+96
-0
lines changed
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
# Guide for migrating to azure-eventgrid v2.0 from azure-eventgrid v1.3
2+
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.
4+
5+
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.
6+
7+
## Table of contents
8+
9+
* [Migration benefits](#migration-benefits)
10+
- [Cross Service SDK improvements](#cross-service-sdk-improvements)
11+
* [Important Changes](#important-changes)
12+
- [Support for Cloud Events](#support-for-cloud-events)
13+
- [Client Constructors](#client-constructors)
14+
- [Publishing Events](#publishing-events)
15+
- [Consuming Events](#consuming-events)
16+
* [Additional Samples](#additional-samples)
17+
18+
## Migration benefits
19+
20+
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.
21+
22+
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.
23+
24+
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) 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.
25+
26+
### Cross Service SDK improvements
27+
28+
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
29+
- a unified logging and diagnostics pipeline offering a common view of the activities across each of the client libraries
30+
- using the new [`azure-identity`](https://github.com/Azure/azure-sdk-for-python/blob/master/sdk/identity/azure-identity/README.md) library to share a single authentication approach between clients
31+
32+
## Important changes
33+
34+
### Support for Cloud Events
35+
36+
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 as a dictionary as follows:
37+
38+
```Python
39+
from azure.eventgrid import CloudEvent
40+
41+
cloud_event = CloudEvent(
42+
type="Contoso.Items.ItemReceived",
43+
source="/contoso/items",
44+
data={
45+
"itemSku": "Contoso Item SKU #1"
46+
},
47+
subject="Door1"
48+
)
49+
50+
# as a dictionary
51+
52+
cloud_event = {
53+
"type":"a0517898-9fa4-4e70-b4a3-afda1dd68672",
54+
"source":"/subscriptions/{subscription-id}/resourceGroups/{resource-group}/providers/Microsoft.Storage/storageAccounts/{storage-account}",
55+
"data": {"hello": "world"},
56+
"subject": "Door1"
57+
}
58+
```
59+
60+
### Client constructors
61+
62+
* The `EventGridClient` in the v1.3 has been replaced with `EventGridPublisherClient`.
63+
64+
| In v1.3 | Equivalent in v2.0 | Sample |
65+
|---|---|---|
66+
|`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)|
67+
68+
* Additionally, we now have an `EventGridConsumer` that should be used to deserialize the events. This class is used only to decode data into a `CloudEvent` or an `EventGridEvent`. Hence, there are no credentials required to construct this as shown below.
69+
70+
```Python
71+
from azure.eventgrid import EventGridConsumer
72+
73+
eg_consumer = EventGridConsumer()
74+
```
75+
76+
### Publishing Events
77+
78+
The `publish_events` API is replaced with `send` in v2.0. Additionally, `send` API accepts `CloudEvent`, `CustomEvent` along with `EventGridEvent`
79+
80+
| In v1.3 | Equivalent in v2.0 | Sample |
81+
|---|---|---|
82+
|`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)|
83+
84+
### Consuming Events
85+
86+
In v2.0, `EventGridConsumer` can be used to decode both Cloud Events and EventGrid Events. Please find the samples [here](https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/eventgrid/azure-eventgrid/samples/consume_samples) to see detailed examples of the consumer.
87+
88+
```Python
89+
EventGridConsumer().decode_cloud_event(cloud_event_dict)
90+
91+
EventGridConsumer().decode_eventgrid_event(eventgrid_event_dict)
92+
```
93+
94+
## Additional samples
95+
96+
More examples can be found at [here](https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/eventgrid/azure-eventgrid/samples)

0 commit comments

Comments
 (0)