Skip to content

Commit 127b307

Browse files
authored
[EventHubs]Update async samples (Azure#21857)
1 parent a57425e commit 127b307

16 files changed

+22
-33
lines changed

sdk/eventhub/azure-eventhub/samples/async_samples/authenticate_with_sas_token_async.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ async def create_with_sas_token():
8383
await producer_client.send_batch(event_data_batch)
8484

8585

86-
loop = asyncio.get_event_loop()
8786
start_time = time.time()
88-
loop.run_until_complete(create_with_sas_token())
87+
asyncio.run(create_with_sas_token())
8988
print("Send messages in {} seconds.".format(time.time() - start_time))

sdk/eventhub/azure-eventhub/samples/async_samples/client_identity_authentication_async.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,6 @@ async def run():
6161
break
6262
await producer.send_batch(event_data_batch)
6363

64-
loop = asyncio.get_event_loop()
65-
loop.run_until_complete(run())
64+
65+
asyncio.run(run())
6666
print('Finished sending.')

sdk/eventhub/azure-eventhub/samples/async_samples/connection_string_authentication_async.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
CONNECTION_STR = os.environ["EVENT_HUB_CONN_STR"]
1616
EVENTHUB_NAME = os.environ['EVENT_HUB_NAME']
1717

18+
1819
async def main():
1920
consumer_client = EventHubConsumerClient.from_connection_string(
2021
conn_str=CONNECTION_STR,
@@ -24,6 +25,6 @@ async def main():
2425
async with consumer_client:
2526
pass # consumer_client is now ready to be used.
2627

28+
2729
if __name__ == '__main__':
28-
loop = asyncio.get_event_loop()
29-
loop.run_until_complete(main())
30+
asyncio.run(main())

sdk/eventhub/azure-eventhub/samples/async_samples/iot_hub_connection_string_receive_async.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,5 +123,4 @@ async def on_event_batch(partition_context, events):
123123

124124
if __name__ == '__main__':
125125
iothub_conn_str = os.environ["IOTHUB_CONN_STR"]
126-
loop = asyncio.get_event_loop()
127-
loop.run_until_complete(receive_events_from_iothub(iothub_conn_str))
126+
asyncio.run(receive_events_from_iothub(iothub_conn_str))

sdk/eventhub/azure-eventhub/samples/async_samples/proxy_async.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,4 @@ async def main():
6161
print('Finished receiving.')
6262

6363

64-
loop = asyncio.get_event_loop()
65-
loop.run_until_complete(main())
66-
64+
asyncio.run(main())

sdk/eventhub/azure-eventhub/samples/async_samples/receive_batch_with_checkpoint_async.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,5 +55,4 @@ async def receive_batch():
5555

5656

5757
if __name__ == '__main__':
58-
loop = asyncio.get_event_loop()
59-
loop.run_until_complete(receive_batch())
58+
asyncio.run(receive_batch())

sdk/eventhub/azure-eventhub/samples/async_samples/recv_async.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,6 @@ async def main():
6363
starting_position="-1", # "-1" is from the beginning of the partition.
6464
)
6565

66+
6667
if __name__ == '__main__':
67-
loop = asyncio.get_event_loop()
68-
loop.run_until_complete(main())
68+
asyncio.run(main())

sdk/eventhub/azure-eventhub/samples/async_samples/recv_for_period_async.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,6 @@ async def main():
7373

7474
print('Consumer has stopped receiving, end time is {}.'.format(time.time()))
7575

76+
7677
if __name__ == '__main__':
77-
loop = asyncio.get_event_loop()
78-
loop.run_until_complete(main())
78+
asyncio.run(main())

sdk/eventhub/azure-eventhub/samples/async_samples/recv_track_last_enqueued_event_prop_async.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,5 +46,4 @@ async def main():
4646

4747

4848
if __name__ == '__main__':
49-
loop = asyncio.get_event_loop()
50-
loop.run_until_complete(main())
49+
asyncio.run(main())

sdk/eventhub/azure-eventhub/samples/async_samples/recv_with_checkpoint_by_event_count_async.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,5 +65,4 @@ async def main():
6565

6666

6767
if __name__ == '__main__':
68-
loop = asyncio.get_event_loop()
69-
loop.run_until_complete(main())
68+
asyncio.run(main())

0 commit comments

Comments
 (0)