diff --git a/sdk/eventhub/azure-eventhubs/HISTORY.md b/sdk/eventhub/azure-eventhubs/HISTORY.md index bf2ada9d12f2..4c56f0eac0fb 100644 --- a/sdk/eventhub/azure-eventhubs/HISTORY.md +++ b/sdk/eventhub/azure-eventhubs/HISTORY.md @@ -18,6 +18,20 @@ - `on_error(partition_context, exception` called when errors occur. - `on_partition_initialize(partition_context)` called when a partition consumer is opened. - `on_partition_close(partition_context, reason)` called when a partition consumer is closed. +- Some modules and classes that were importable from several different places have been removed: + - `azure.eventhub.common` has been removed. Import from `azure.eventhub` instead. + - `azure.eventhub.client_abstract` has been removed. Use `azure.eventhub.EventHubProducerClient` or `azure.eventhub.EventHubConsumerClient` instead. + - `azure.eventhub.client` has been removed. Use `azure.eventhub.EventHubProducerClient` or `azure.eventhub.EventHubConsumerClient` instead. + - `azure.eventhub.producer` has been removed. Use `azure.eventhub.EventHubProducerClient` instead. + - `azure.eventhub.consumer` has been removed. Use `azure.eventhub.EventHubConsumerClient` instead. + - `azure.eventhub.aio.client_async` has been removed. Use `azure.eventhub.aio.EventHubProducerClient` or `azure.eventhub.aio.EventHubConsumerClient` instead. + - `azure.eventhub.aio.producer_async` has been removed. Use `azure.eventhub.aio.EventHubProducerClient` instead. + - `azure.eventhub.aio.consumer_async` has been removed. Use `azure.eventhub.aio.EventHubConsumerClient` instead. + - `azure.eventhub.aio.event_processor.event_processor` has been removed. Use `azure.eventhub.aio.EventHubConsumerClient` instead. + - `azure.eventhub.aio.event_processor.partition_processor` has been removed. Use callback methods instead. + - `azure.eventhub.aio.event_processor.partition_manager` has been removed. Import from `azure.eventhub.aio` instead. + - `azure.eventhub.aio.event_processor.partition_context` has been removed. Import from `azure.eventhub.aio` instead. + - `azure.eventhub.aio.event_processor.sample_partition_manager` has been removed. **Bug fixes** diff --git a/sdk/eventhub/azure-eventhubs/azure/eventhub/common.py b/sdk/eventhub/azure-eventhubs/azure/eventhub/common.py index 38f6caa2e185..d48f0cd27a41 100644 --- a/sdk/eventhub/azure-eventhubs/azure/eventhub/common.py +++ b/sdk/eventhub/azure-eventhubs/azure/eventhub/common.py @@ -280,7 +280,7 @@ def body_as_str(self, encoding='UTF-8'): :param encoding: The encoding to use for decoding message data. Default is 'UTF-8' - :rtype: str or unicode + :rtype: str """ data = self.body try: diff --git a/sdk/eventhub/azure-eventhubs/samples/async_samples/recv_async.py b/sdk/eventhub/azure-eventhubs/samples/async_samples/recv_async.py index eddf2802c915..591234613edb 100644 --- a/sdk/eventhub/azure-eventhubs/samples/async_samples/recv_async.py +++ b/sdk/eventhub/azure-eventhubs/samples/async_samples/recv_async.py @@ -33,18 +33,16 @@ async def receive(client): await client.receive(on_events=on_events, consumer_group="$default") except KeyboardInterrupt: - client.close() + await client.close() -if __name__ == '__main__': - loop = asyncio.get_event_loop() +async def main(): client = EventHubConsumerClient.from_connection_string( CONNECTION_STR, ) - try: - loop.run_until_complete(receive(client)) - except KeyboardInterrupt: - pass - finally: - loop.run_until_complete(client.close()) - loop.stop() + async with client: + await receive(client) + +if __name__ == '__main__': + loop = asyncio.get_event_loop() + loop.run_until_complete(main()) diff --git a/sdk/eventhub/azure-eventhubs/samples/async_samples/recv_track_last_enqueued_event_info_async.py b/sdk/eventhub/azure-eventhubs/samples/async_samples/recv_track_last_enqueued_event_info_async.py index e4d3fac74968..f8b1266437ed 100644 --- a/sdk/eventhub/azure-eventhubs/samples/async_samples/recv_track_last_enqueued_event_info_async.py +++ b/sdk/eventhub/azure-eventhubs/samples/async_samples/recv_track_last_enqueued_event_info_async.py @@ -37,20 +37,20 @@ async def receive(client): try: await client.receive(on_events=on_events, consumer_group="$default", - partition_id='0') + partition_id='0', + track_last_enqueued_event_properties=True) except KeyboardInterrupt: - client.close() + await client.close() -if __name__ == '__main__': - loop = asyncio.get_event_loop() +async def main(): client = EventHubConsumerClient.from_connection_string( CONNECTION_STR, ) - try: - loop.run_until_complete(receive(client)) - except KeyboardInterrupt: - pass - finally: - loop.run_until_complete(client.close()) - loop.stop() + async with client: + await receive(client) + + +if __name__ == '__main__': + loop = asyncio.get_event_loop() + loop.run_until_complete(main()) diff --git a/sdk/eventhub/azure-eventhubs/samples/async_samples/recv_with_partition_manager_async.py b/sdk/eventhub/azure-eventhubs/samples/async_samples/recv_with_partition_manager_async.py index 9353a6041a87..92fea01ba678 100644 --- a/sdk/eventhub/azure-eventhubs/samples/async_samples/recv_with_partition_manager_async.py +++ b/sdk/eventhub/azure-eventhubs/samples/async_samples/recv_with_partition_manager_async.py @@ -46,21 +46,20 @@ async def receive(client): # With specified partition_id, load-balance will be disabled # await client.receive(event_handler=event_handler, consumer_group="$default", partition_id = '0')) except KeyboardInterrupt: - client.close() + await client.close() -if __name__ == '__main__': - loop = asyncio.get_event_loop() +async def main(): container_client = ContainerClient.from_connection_string(STORAGE_CONNECTION_STR, "eventprocessor") partition_manager = BlobPartitionManager(container_client) client = EventHubConsumerClient.from_connection_string( CONNECTION_STR, partition_manager=partition_manager, # For load balancing and checkpoint. Leave None for no load balancing ) - try: - loop.run_until_complete(receive(client)) - except KeyboardInterrupt: - pass - finally: - loop.run_until_complete(client.close()) - loop.stop() + async with client: + await receive(client) + + +if __name__ == '__main__': + loop = asyncio.get_event_loop() + loop.run_until_complete(main()) diff --git a/sdk/eventhub/azure-eventhubs/samples/sync_samples/sample_code_eventhub.py b/sdk/eventhub/azure-eventhubs/samples/sync_samples/sample_code_eventhub.py index 5869060be95e..aa45e23fdf11 100644 --- a/sdk/eventhub/azure-eventhubs/samples/sync_samples/sample_code_eventhub.py +++ b/sdk/eventhub/azure-eventhubs/samples/sync_samples/sample_code_eventhub.py @@ -71,10 +71,7 @@ def example_eventhub_sync_send_and_receive(): event_data = EventData("String data") event_data = EventData(b"Bytes data") - event_data = EventData([b"A", b"B", b"C"]) - list_data = ['Message {}'.format(i) for i in range(10)] - event_data = EventData(body=list_data) # [END create_event_data] # [START eventhub_producer_client_create_batch_sync] diff --git a/sdk/eventhub/azure-eventhubs/tests/livetest/synctests/test_consumer_client.py b/sdk/eventhub/azure-eventhubs/tests/livetest/synctests/test_consumer_client.py index 18105de695fe..ee007256fb72 100644 --- a/sdk/eventhub/azure-eventhubs/tests/livetest/synctests/test_consumer_client.py +++ b/sdk/eventhub/azure-eventhubs/tests/livetest/synctests/test_consumer_client.py @@ -1,6 +1,7 @@ import time import pytest import threading +import sys from azure.eventhub import EventData from azure.eventhub import EventHubConsumerClient from azure.eventhub._eventprocessor.local_partition_manager import InMemoryPartitionManager @@ -54,6 +55,9 @@ def on_events(partition_context, events): @pytest.mark.liveTest def test_receive_load_balancing(connstr_senders): + if sys.platform.startswith('darwin'): + pytest.skip("Skipping on OSX - test code using multiple threads. Sometimes OSX aborts python process") + connection_str, senders = connstr_senders pm = InMemoryPartitionManager() client1 = EventHubConsumerClient.from_connection_string(