diff --git a/sdk/eventgrid/azure-eventgrid/azure/eventgrid/aio/_publisher_client_async.py b/sdk/eventgrid/azure-eventgrid/azure/eventgrid/aio/_publisher_client_async.py index 5029e9a5f963..b6abc8d3f1a8 100644 --- a/sdk/eventgrid/azure-eventgrid/azure/eventgrid/aio/_publisher_client_async.py +++ b/sdk/eventgrid/azure-eventgrid/azure/eventgrid/aio/_publisher_client_async.py @@ -134,14 +134,14 @@ async def send(self, events: SendType, **kwargs: Any) -> None: :start-after: [START publish_eg_event_dict_async] :end-before: [END publish_eg_event_dict_async] :language: python - :dedent: 0 + :dedent: 4 :caption: Publishing an EventGridEvent using a dict-like representation. .. literalinclude:: ../samples/async_samples/sample_publish_cloud_event_using_dict_async.py :start-after: [START publish_cloud_event_dict_async] :end-before: [END publish_cloud_event_dict_async] :language: python - :dedent: 0 + :dedent: 4 :caption: Publishing a CloudEvent using a dict-like representation. When publishing a Custom Schema Event(s), dict-like representation is accepted. @@ -153,7 +153,7 @@ async def send(self, events: SendType, **kwargs: Any) -> None: :start-after: [START publish_custom_schema_async] :end-before: [END publish_custom_schema_async] :language: python - :dedent: 0 + :dedent: 4 :caption: Publishing a Custom Schema event. **WARNING**: To gain the best performance when sending multiple events at one time, diff --git a/sdk/eventgrid/azure-eventgrid/samples/consume_samples/consume_cloud_events_from_eventhub.py b/sdk/eventgrid/azure-eventgrid/samples/consume_samples/consume_cloud_events_from_eventhub.py index c831c53f6a16..27f56126da72 100644 --- a/sdk/eventgrid/azure-eventgrid/samples/consume_samples/consume_cloud_events_from_eventhub.py +++ b/sdk/eventgrid/azure-eventgrid/samples/consume_samples/consume_cloud_events_from_eventhub.py @@ -14,8 +14,8 @@ 3) EVENTHUB_NAME: The name of the eventhub account """ import os - -from azure.eventgrid import CloudEvent, EventGridEvent +import json +from azure.core.messaging import CloudEvent from azure.eventhub import EventHubConsumerClient CONNECTION_STR = os.environ["EVENT_HUB_CONN_STR"] @@ -23,22 +23,10 @@ def on_event(partition_context, event): + + dict_event = CloudEvent.from_dict(json.loads(event)[0]) + print("data: {}\n".format(deserialized_event.data)) - dict_event = event.body_as_json()[0] - deserialized_event = eg_consumer.deserialize_eventgrid_events(dict_event) - if deserialized_event.model.__class__ == CloudEvent: - dict_event = deserialized_event.to_json() - print("event.type: {}\n".format(dict_event["type"])) - print("event.to_json(): {}\n".format(dict_event)) - print("model: {}\n".format(deserialized_event.model)) - print("model.data: {}\n".format(deserialized_event.model.data)) - else: - dict_event = deserialized_event.to_json() - print("event.to_json(): {}\n".format(dict_event)) - print("model: {}\n".format(deserialized_event.model)) - print("model.data: {}\n".format(deserialized_event.model.data)) - -eg_consumer = EventGridDeserializer() consumer_client = EventHubConsumerClient.from_connection_string( conn_str=CONNECTION_STR, consumer_group='$Default', diff --git a/sdk/eventgrid/azure-eventgrid/samples/consume_samples/functionsapp/EventGridTrigger1/__init__.py b/sdk/eventgrid/azure-eventgrid/samples/consume_samples/functionsapp/EventGridTrigger1/__init__.py index 36abf8806643..460aa49b171e 100644 --- a/sdk/eventgrid/azure-eventgrid/samples/consume_samples/functionsapp/EventGridTrigger1/__init__.py +++ b/sdk/eventgrid/azure-eventgrid/samples/consume_samples/functionsapp/EventGridTrigger1/__init__.py @@ -3,7 +3,7 @@ import sys import azure.functions as func -from azure.eventgrid import EventGridDeserializer +from azure.eventgrid import EventGridEvent def main(event: func.EventGridEvent): logging.info(sys.version) @@ -16,7 +16,6 @@ def main(event: func.EventGridEvent): 'event_type': event.event_type }) logging.info(result) - consumer = EventGridDeserializer() - deserialized_event = consumer.deserialize_events(result) + deserialized_event = EventGridEvent.from_dict(json.loads(result)) ## can only be EventGridEvent print("model: {}".format(event.model))