diff --git a/sdk/eventhub/azure-eventhub-checkpointstoreblob-aio/README.md b/sdk/eventhub/azure-eventhub-checkpointstoreblob-aio/README.md index c342480b90a7..4e3305647dd1 100644 --- a/sdk/eventhub/azure-eventhub-checkpointstoreblob-aio/README.md +++ b/sdk/eventhub/azure-eventhub-checkpointstoreblob-aio/README.md @@ -74,7 +74,7 @@ storage_connection_str = '<< CONNECTION STRING OF THE STORAGE >>' container_name = '<< STORAGE CONTAINER NAME>>' async def on_event(partition_context, event): - # do something + # Put your code here. await partition_context.update_checkpoint(event) # Or update_checkpoint every N events for better performance. async def main(): @@ -89,10 +89,8 @@ async def main(): checkpoint_store=checkpoint_store, ) - try: + async with client: await client.receive(on_event) - except KeyboardInterrupt: - await client.close() if __name__ == '__main__': loop = asyncio.get_event_loop() diff --git a/sdk/eventhub/azure-eventhub-checkpointstoreblob/README.md b/sdk/eventhub/azure-eventhub-checkpointstoreblob/README.md index 53c262cf1915..f0f958fee642 100644 --- a/sdk/eventhub/azure-eventhub-checkpointstoreblob/README.md +++ b/sdk/eventhub/azure-eventhub-checkpointstoreblob/README.md @@ -72,8 +72,8 @@ storage_connection_str = '<< CONNECTION STRING OF THE STORAGE >>' container_name = '<< STORAGE CONTAINER NAME>>' -def process_events(partition_context, event): - # do something +def on_event(partition_context, event): + # Put your code here. partition_context.update_checkpoint(event) # Or update_checkpoint every N events for better performance. def main(): @@ -88,10 +88,8 @@ def main(): checkpoint_store=checkpoint_store, ) - try: - client.receive(process_events) - except KeyboardInterrupt: - client.close() + with client: + client.receive(on_event) if __name__ == '__main__': main() diff --git a/sdk/eventhub/azure-eventhub/README.md b/sdk/eventhub/azure-eventhub/README.md index 0cd12f1f2eaa..cba5a2a7ec63 100644 --- a/sdk/eventhub/azure-eventhub/README.md +++ b/sdk/eventhub/azure-eventhub/README.md @@ -69,10 +69,10 @@ from azure.identity import DefaultAzureCredential credential = DefaultAzureCredential() -host = '<< HOSTNAME OF THE EVENT HUB >>' +fully_qualified_namespace = '<< HOSTNAME OF THE EVENT HUB >>' eventhub_name = '<< NAME OF THE EVENT HUB >>' consumer_group = '<< CONSUMER GROUP >>' -consumer_client = EventHubConsumerClient(host, eventhub_name, consumer_group, credential) +consumer_client = EventHubConsumerClient(fully_qualified_namespace, eventhub_name, consumer_group, credential) ``` @@ -297,13 +297,10 @@ async def on_event(partition_context, event): await partition_context.update_checkpoint(event) # Or update_checkpoint every N events for better performance. async def receive(client): - try: - await client.receive( - on_event=on_event, - starting_position="-1", # "-1" is from the beginning of the partition. - ) - except KeyboardInterrupt: - await client.close() + await client.receive( + on_event=on_event, + starting_position="-1", # "-1" is from the beginning of the partition. + ) async def main(): checkpoint_store = BlobCheckpointStore.from_connection_string(storage_connection_str, container_name)