Skip to content

Commit 36f2003

Browse files
Rakshith Bhyravabhotlaswathipil
Rakshith Bhyravabhotla
andauthored
[EventGrid] Improve docs (Azure#16986)
* intital * read me improvements * migration guide * blundera * nit * Apply suggestions from code review Co-authored-by: swathipil <[email protected]> Co-authored-by: swathipil <[email protected]>
1 parent adfce6b commit 36f2003

8 files changed

+219
-19
lines changed

sdk/eventgrid/azure-eventgrid/README.md

+188-13
Large diffs are not rendered by default.

sdk/eventgrid/azure-eventgrid/azure/eventgrid/_models.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ class EventGridEvent(InternalEventGridEvent, EventMixin):
173173
If not provided, will be stamped with an empty value.
174174
:type data_version: str
175175
:keyword topic: Optional. The resource path of the event source. If not provided, Event Grid will
176-
stamp onto the event.
176+
stamp onto the event. This is required when sending event(s) to a domain.
177177
:type topic: str
178178
:keyword metadata_version: Optional. The schema version of the event metadata. If provided,
179179
must match Event Grid Schema exactly. If not provided, EventGrid will stamp onto event.

sdk/eventgrid/azure-eventgrid/migration_guide.md

+24-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ The modern Event Grid client library also provides the ability to share in some
3636
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:
3737

3838
```Python
39-
from azure.eventgrid import CloudEvent
39+
from azure.core.messaging import CloudEvent
4040

4141
cloud_event = CloudEvent(
4242
type="Contoso.Items.ItemReceived",
@@ -73,6 +73,29 @@ The `publish_events` API is replaced with `send` in v2.0. Additionally, `send` A
7373
|---|---|---|
7474
|`EventGridClient(credentials).publish_events(topic_hostname, events)`|`EventGridPublisherClient(endpoint, credential).send(events)`|[Sample for client construction](https://github.com/Azure/azure-sdk-for-python/blob/master/sdk/eventgrid/azure-eventgrid/samples/sync_samples/sample_publish_events_using_cloud_events_1.0_schema.py)|
7575

76+
### Consuming Events
77+
78+
The v2.x major version supports deserializing dictionaries into strongly typed objects. The `from_dict` methods in the `CloudEvent` and `EventGridEvent` models can be used for the same.
79+
80+
This example consumes a payload message received from ServiceBus and deserializes it to an EventGridEvent object.
81+
82+
```Python
83+
from azure.eventgrid import EventGridEvent
84+
from azure.servicebus import ServiceBusClient
85+
import os
86+
import json
87+
88+
# all types of EventGridEvents below produce same DeserializedEvent
89+
connection_str = os.environ['SERVICE_BUS_CONN_STR']
90+
queue_name = os.environ['SERVICE_BUS_QUEUE_NAME']
91+
92+
with ServiceBusClient.from_connection_string(connection_str) as sb_client:
93+
payload = sb_client.get_queue_receiver(queue_name).receive_messages()
94+
95+
## deserialize payload into a list of typed Events
96+
events = [EventGridEvent.from_dict(json.loads(next(msg.body).decode('utf-8'))) for msg in payload]
97+
```
98+
7699
## Additional samples
77100

78101
More examples can be found at [here](https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/eventgrid/azure-eventgrid/samples)

sdk/eventgrid/azure-eventgrid/samples/README.md

+2
Original file line numberDiff line numberDiff line change
@@ -71,4 +71,6 @@ To publish events, dict representation of the models could also be used as follo
7171
[python-eg-publish-samples]: https://github.com/Azure/azure-sdk-for-python/blob/master/sdk/eventgrid/azure-eventgrid/samples/publish_samples
7272
[python-eg-consume-samples]: https://github.com/Azure/azure-sdk-for-python/blob/master/sdk/eventgrid/azure-eventgrid/samples/consume_samples
7373

74+
[python-eg-sample-consume-custom-payload]: https://github.com/Azure/azure-sdk-for-python/blob/master/sdk/eventgrid/azure-eventgrid/samples/sync_samples/sample_consume_custom_payload.py
75+
7476
[publisher-service-doc]: https://docs.microsoft.com/azure/event-grid/concepts

sdk/eventgrid/azure-eventgrid/samples/async_samples/sample_publish_cloud_event_using_dict_async.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ async def publish():
3030

3131
# [START publish_cloud_event_dict_async]
3232
async with client:
33-
client.send([
33+
await client.send([
3434
{
3535
"type": "Contoso.Items.ItemReceived",
3636
"source": "/contoso/items",

sdk/eventgrid/azure-eventgrid/samples/async_samples/sample_publish_events_using_cloud_events_1.0_schema_async.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ async def publish():
2828
credential = AzureKeyCredential(topic_key)
2929
client = EventGridPublisherClient(endpoint, credential)
3030

31-
client.send([
31+
await client.send([
3232
CloudEvent(
3333
type="Contoso.Items.ItemReceived",
3434
source="/contoso/items",

sdk/eventgrid/azure-eventgrid/samples/consume_samples/consume_cloud_events_from_storage_queue.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
message_decode_policy=BinaryBase64DecodePolicy()
3030
).peek_messages()
3131

32-
## deserialize payload into a lost of typed Events
32+
## deserialize payload into a list of typed Events
3333
events = [CloudEvent.from_dict(json.loads(msg.content)) for msg in payload]
3434

3535
for event in events:

sdk/eventgrid/azure-eventgrid/samples/consume_samples/consume_eventgrid_events_from_service_bus_queue.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
with ServiceBusClient.from_connection_string(connection_str) as sb_client:
2626
payload = sb_client.get_queue_receiver(queue_name).receive_messages()
2727

28-
## deserialize payload into a lost of typed Events
28+
## deserialize payload into a list of typed Events
2929
events = [EventGridEvent.from_dict(json.loads(next(msg.body).decode('utf-8'))) for msg in payload]
3030

3131
for event in events:

0 commit comments

Comments
 (0)