diff --git a/sdk/eventhub/azure-eventhubs-checkpointstoreblob-aio/MANIFEST.in b/sdk/eventhub/azure-eventhubs-checkpointstoreblob-aio/MANIFEST.in index 7012aaaa132a..4adc07aad2ed 100644 --- a/sdk/eventhub/azure-eventhubs-checkpointstoreblob-aio/MANIFEST.in +++ b/sdk/eventhub/azure-eventhubs-checkpointstoreblob-aio/MANIFEST.in @@ -2,3 +2,5 @@ include *.md include azure/__init__.py include azure/eventhub/__init__.py include azure/eventhub/extensions/__init__.py +recursive-include tests *.py *.yaml +recursive-include samples *.py \ No newline at end of file diff --git a/sdk/eventhub/azure-eventhubs-checkpointstoreblob-aio/README.md b/sdk/eventhub/azure-eventhubs-checkpointstoreblob-aio/README.md index 2733803eed1c..a7abbaf01131 100644 --- a/sdk/eventhub/azure-eventhubs-checkpointstoreblob-aio/README.md +++ b/sdk/eventhub/azure-eventhubs-checkpointstoreblob-aio/README.md @@ -5,7 +5,7 @@ This Checkpoint Store package works as a plug-in package to `EventHubConsumerCli Please note that this is an async library, for sync version of the Azure EventHubs Checkpoint Store client library, please refer to [azure-eventhubs-checkpointstoreblob](https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/eventhub/azure-eventhubs-checkpointstoreblob). -[Source code](https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/eventhub/azure-eventhubs-checkpointstoreblob-aio) | [Package (PyPi)](https://pypi.org/project/azure-eventhub-checkpointstoreblob-aio/) | [API reference documentation](https://azuresdkdocs.blob.core.windows.net/$web/python/azure-eventhub/5.0.0b5/azure.eventhub.extensions.html) | [Azure Eventhubs documentation](https://docs.microsoft.com/en-us/azure/event-hubs/) | [Azure Storage documentation](https://docs.microsoft.com/en-us/azure/storage/) +[Source code](https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/eventhub/azure-eventhubs-checkpointstoreblob-aio) | [Package (PyPi)](https://pypi.org/project/azure-eventhub-checkpointstoreblob-aio/) | [API reference documentation](https://azuresdkdocs.blob.core.windows.net/$web/python/azure-eventhub/5.0.0b5/azure.eventhub.aio.html#azure.eventhub.aio.PartitionManager) | [Azure Eventhubs documentation](https://docs.microsoft.com/en-us/azure/event-hubs/) | [Azure Storage documentation](https://docs.microsoft.com/en-us/azure/storage/) ## Getting started diff --git a/sdk/eventhub/azure-eventhubs-checkpointstoreblob/MANIFEST.in b/sdk/eventhub/azure-eventhubs-checkpointstoreblob/MANIFEST.in index 7012aaaa132a..4adc07aad2ed 100644 --- a/sdk/eventhub/azure-eventhubs-checkpointstoreblob/MANIFEST.in +++ b/sdk/eventhub/azure-eventhubs-checkpointstoreblob/MANIFEST.in @@ -2,3 +2,5 @@ include *.md include azure/__init__.py include azure/eventhub/__init__.py include azure/eventhub/extensions/__init__.py +recursive-include tests *.py *.yaml +recursive-include samples *.py \ No newline at end of file diff --git a/sdk/eventhub/azure-eventhubs-checkpointstoreblob/README.md b/sdk/eventhub/azure-eventhubs-checkpointstoreblob/README.md index 1b47a54ecd35..07cfd57bc247 100644 --- a/sdk/eventhub/azure-eventhubs-checkpointstoreblob/README.md +++ b/sdk/eventhub/azure-eventhubs-checkpointstoreblob/README.md @@ -5,7 +5,7 @@ This Checkpoint Store package works as a plug-in package to `EventHubConsumerCli Please note that this is a sync library, for async version of the Azure EventHubs Checkpoint Store client library, please refer to [azure-eventhubs-checkpointstoreblob-aio](https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/eventhub/azure-eventhubs-checkpointstoreblob-aio). -[Source code](https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/eventhub/azure-eventhubs-checkpointstoreblob) | [Package (PyPi)](https://pypi.org/project/azure-eventhub-checkpointstoreblob/) | [API reference documentation](https://azuresdkdocs.blob.core.windows.net/$web/python/azure-eventhub/5.0.0b5/azure.eventhub.extensions.html) | [Azure Eventhubs documentation](https://docs.microsoft.com/en-us/azure/event-hubs/) | [Azure Storage documentation](https://docs.microsoft.com/en-us/azure/storage/) +[Source code](https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/eventhub/azure-eventhubs-checkpointstoreblob) | [Package (PyPi)](https://pypi.org/project/azure-eventhub-checkpointstoreblob/) | [API reference documentation](https://azuresdkdocs.blob.core.windows.net/$web/python/azure-eventhub/5.0.0b5/azure.eventhub.html#azure.eventhub.PartitionManager) | [Azure Eventhubs documentation](https://docs.microsoft.com/en-us/azure/event-hubs/) | [Azure Storage documentation](https://docs.microsoft.com/en-us/azure/storage/) ## Getting started diff --git a/sdk/eventhub/azure-eventhubs/HISTORY.md b/sdk/eventhub/azure-eventhubs/HISTORY.md index a1d4d9f2b1b8..bf2ada9d12f2 100644 --- a/sdk/eventhub/azure-eventhubs/HISTORY.md +++ b/sdk/eventhub/azure-eventhubs/HISTORY.md @@ -4,7 +4,7 @@ **Breaking changes** -- `EventHubClient` has been split into two separate clients: `EventHubProducerClient` and `EventHubConsumerClient`. +- `EventHubClient`, `EventHubConsumer` and `EventHubProducer` has been removed. Use `EventHubProducerClient` and `EventHubConsumerClient` instead. - Construction of both objects is the same as it was for the previous client. - Introduced `EventHubProducerClient` as substitution for`EventHubProducer`. - `EventHubProducerClient` supports sending events to different partitions. diff --git a/sdk/eventhub/azure-eventhubs/azure/eventhub/_consumer_client.py b/sdk/eventhub/azure-eventhubs/azure/eventhub/_consumer_client.py index fc06a7f58445..cbf7f299ac51 100644 --- a/sdk/eventhub/azure-eventhubs/azure/eventhub/_consumer_client.py +++ b/sdk/eventhub/azure-eventhubs/azure/eventhub/_consumer_client.py @@ -106,7 +106,7 @@ def from_connection_string(cls, conn_str, **kwargs): :param str conn_str: The connection string of an eventhub. :keyword str event_hub_path: The path of the specific Event Hub to connect the client to. :keyword bool network_tracing: Whether to output network trace logs to the logger. Default is `False`. - :keyword dict[str, Any] http_proxy: HTTP proxy settings. This must be a dictionary with the following + :keyword dict[str,Any] http_proxy: HTTP proxy settings. This must be a dictionary with the following keys - 'proxy_hostname' (str value) and 'proxy_port' (int value). Additionally the following keys may also be present - 'username', 'password'. :keyword float auth_timeout: The time in seconds to wait for a token to be authorized by the service. @@ -124,6 +124,16 @@ def from_connection_string(cls, conn_str, **kwargs): :paramtype partition_manager: ~azure.eventhub.PartitionManager :keyword float load_balancing_interval: When load balancing kicks in, this is the interval in seconds between two load balancing. Default is 10. + + .. admonition:: Example: + + .. literalinclude:: ../samples/sync_samples/sample_code_eventhub.py + :start-after: [START create_eventhub_consumer_client_from_conn_str_sync] + :end-before: [END create_eventhub_consumer_client_from_conn_str_sync] + :language: python + :dedent: 4 + :caption: Create a new instance of the EventHubConsumerClient from connection string. + """ return super(EventHubConsumerClient, cls).from_connection_string(conn_str, **kwargs) diff --git a/sdk/eventhub/azure-eventhubs/azure/eventhub/_eventprocessor/partition_manager.py b/sdk/eventhub/azure-eventhubs/azure/eventhub/_eventprocessor/partition_manager.py index c90d2dceaf7d..db8545bd84da 100644 --- a/sdk/eventhub/azure-eventhubs/azure/eventhub/_eventprocessor/partition_manager.py +++ b/sdk/eventhub/azure-eventhubs/azure/eventhub/_eventprocessor/partition_manager.py @@ -67,9 +67,10 @@ def update_checkpoint(self, fully_qualified_namespace, eventhub_name, consumer_g the Event Hubs namespace that contains it. :param str consumer_group_name: The name of the consumer group the ownership are associated with. :param str partition_id: The partition id which the checkpoint is created for. - :param str offset: The offset of the ~azure.eventhub.EventData the new checkpoint will be associated with. - :param int sequence_number: The sequence_number of the ~azure.eventhub.EventData the new checkpoint - will be associated with. + :param str offset: The offset of the :class:`EventData` + the new checkpoint will be associated with. + :param int sequence_number: The sequence_number of the :class:`EventData` + the new checkpoint will be associated with. :rtype: None """ diff --git a/sdk/eventhub/azure-eventhubs/azure/eventhub/_producer_client.py b/sdk/eventhub/azure-eventhubs/azure/eventhub/_producer_client.py index 98ea2f3a3aed..02337bc21087 100644 --- a/sdk/eventhub/azure-eventhubs/azure/eventhub/_producer_client.py +++ b/sdk/eventhub/azure-eventhubs/azure/eventhub/_producer_client.py @@ -81,7 +81,7 @@ def from_connection_string(cls, conn_str, **kwargs): :param str conn_str: The connection string of an eventhub. :keyword str event_hub_path: The path of the specific Event Hub to connect the client to. :keyword bool network_tracing: Whether to output network trace logs to the logger. Default is `False`. - :keyword dict[str, Any] http_proxy: HTTP proxy settings. This must be a dictionary with the following + :keyword dict[str,Any] http_proxy: HTTP proxy settings. This must be a dictionary with the following keys - 'proxy_hostname' (str value) and 'proxy_port' (int value). Additionally the following keys may also be present - 'username', 'password'. :keyword float auth_timeout: The time in seconds to wait for a token to be authorized by the service. @@ -92,6 +92,15 @@ def from_connection_string(cls, conn_str, **kwargs): :keyword transport_type: The type of transport protocol that will be used for communicating with the Event Hubs service. Default is `TransportType.Amqp`. :paramtype transport_type: ~azure.eventhub.TransportType + + .. admonition:: Example: + + .. literalinclude:: ../samples/sync_samples/sample_code_eventhub.py + :start-after: [START create_eventhub_producer_client_from_conn_str_sync] + :end-before: [END create_eventhub_producer_client_from_conn_str_sync] + :language: python + :dedent: 4 + :caption: Create a new instance of the EventHubProducerClient from connection string. """ return super(EventHubProducerClient, cls).from_connection_string(conn_str, **kwargs) diff --git a/sdk/eventhub/azure-eventhubs/azure/eventhub/aio/_consumer_client_async.py b/sdk/eventhub/azure-eventhubs/azure/eventhub/aio/_consumer_client_async.py index 56972f174d6b..fd09857fe353 100644 --- a/sdk/eventhub/azure-eventhubs/azure/eventhub/aio/_consumer_client_async.py +++ b/sdk/eventhub/azure-eventhubs/azure/eventhub/aio/_consumer_client_async.py @@ -85,7 +85,7 @@ def from_connection_string(cls, conn_str, **kwargs): :param str conn_str: The connection string of an eventhub. :keyword str event_hub_path: The path of the specific Event Hub to connect the client to. :keyword bool network_tracing: Whether to output network trace logs to the logger. Default is `False`. - :keyword dict[str, Any] http_proxy: HTTP proxy settings. This must be a dictionary with the following + :keyword dict[str,Any] http_proxy: HTTP proxy settings. This must be a dictionary with the following keys - 'proxy_hostname' (str value) and 'proxy_port' (int value). Additionally the following keys may also be present - 'username', 'password'. :keyword float auth_timeout: The time in seconds to wait for a token to be authorized by the service. @@ -103,6 +103,16 @@ def from_connection_string(cls, conn_str, **kwargs): :paramtype partition_manager: ~azure.eventhub.aio.PartitionManager :keyword float load_balancing_interval: When load balancing kicks in, this is the interval in seconds between two load balancing. Default is 10. + + .. admonition:: Example: + + .. literalinclude:: ../samples/async_samples/sample_code_eventhub_async.py + :start-after: [START create_eventhub_consumer_client_from_conn_str_async] + :end-before: [END create_eventhub_consumer_client_from_conn_str_async] + :language: python + :dedent: 4 + :caption: Create a new instance of the EventHubConsumerClient from connection string. + """ return super(EventHubConsumerClient, cls).from_connection_string(conn_str, **kwargs) diff --git a/sdk/eventhub/azure-eventhubs/azure/eventhub/aio/_producer_client_async.py b/sdk/eventhub/azure-eventhubs/azure/eventhub/aio/_producer_client_async.py index 79e6b429911b..51f1eff40cfb 100644 --- a/sdk/eventhub/azure-eventhubs/azure/eventhub/aio/_producer_client_async.py +++ b/sdk/eventhub/azure-eventhubs/azure/eventhub/aio/_producer_client_async.py @@ -81,7 +81,7 @@ def from_connection_string(cls, conn_str, **kwargs): :param str conn_str: The connection string of an eventhub. :keyword str event_hub_path: The path of the specific Event Hub to connect the client to. :keyword bool network_tracing: Whether to output network trace logs to the logger. Default is `False`. - :keyword dict[str, Any] http_proxy: HTTP proxy settings. This must be a dictionary with the following + :keyword dict[str,Any] http_proxy: HTTP proxy settings. This must be a dictionary with the following keys - 'proxy_hostname' (str value) and 'proxy_port' (int value). Additionally the following keys may also be present - 'username', 'password'. :keyword float auth_timeout: The time in seconds to wait for a token to be authorized by the service. @@ -92,6 +92,15 @@ def from_connection_string(cls, conn_str, **kwargs): :keyword transport_type: The type of transport protocol that will be used for communicating with the Event Hubs service. Default is `TransportType.Amqp`. :paramtype transport_type: ~azure.eventhub.TransportType + + .. admonition:: Example: + + .. literalinclude:: ../samples/async_samples/sample_code_eventhub_async.py + :start-after: [START create_eventhub_producer_client_from_conn_str_async] + :end-before: [END create_eventhub_producer_client_from_conn_str_async] + :language: python + :dedent: 4 + :caption: Create a new instance of the EventHubProducerClient from connection string. """ return super(EventHubProducerClient, cls).from_connection_string(conn_str, **kwargs) diff --git a/sdk/eventhub/azure-eventhubs/azure/eventhub/aio/eventprocessor/partition_manager.py b/sdk/eventhub/azure-eventhubs/azure/eventhub/aio/eventprocessor/partition_manager.py index f6f8ea18860f..114f9422eedd 100644 --- a/sdk/eventhub/azure-eventhubs/azure/eventhub/aio/eventprocessor/partition_manager.py +++ b/sdk/eventhub/azure-eventhubs/azure/eventhub/aio/eventprocessor/partition_manager.py @@ -65,9 +65,10 @@ async def update_checkpoint(self, fully_qualified_namespace: str, eventhub_name: the Event Hubs namespace that contains it. :param str consumer_group_name: The name of the consumer group the ownership are associated with. :param str partition_id: The partition id which the checkpoint is created for. - :param str offset: The offset of the ~azure.eventhub.EventData the new checkpoint will be associated with. - :param int sequence_number: The sequence_number of the ~azure.eventhub.EventData the new checkpoint - will be associated with. + :param str offset: The offset of the :class:`EventData` + the new checkpoint will be associated with. + :param int sequence_number: The sequence_number of the :class:`EventData` + the new checkpoint will be associated with. :rtype: None """ diff --git a/sdk/eventhub/azure-eventhubs/azure/eventhub/common.py b/sdk/eventhub/azure-eventhubs/azure/eventhub/common.py index 2d203280773a..38f6caa2e185 100644 --- a/sdk/eventhub/azure-eventhubs/azure/eventhub/common.py +++ b/sdk/eventhub/azure-eventhubs/azure/eventhub/common.py @@ -319,7 +319,8 @@ class EventDataBatch(object): Use `try_add` method to add events until the maximum batch size limit in bytes has been reached - a `ValueError` will be raised. - Use `send` method of ~azure.eventhub.EventHubProducerClient or ~azure.eventhub.aio.EventHubProducerClient + Use `send` method of :class:`EventHubProducerClient` + or the async :class:`EventHubProducerClient` for sending. The `send` method accepts partition_key as a parameter for sending a particular partition. **Please use the create_batch method of EventHubProducerClient diff --git a/sdk/eventhub/azure-eventhubs/samples/async_samples/sample_code_eventhub_async.py b/sdk/eventhub/azure-eventhubs/samples/async_samples/sample_code_eventhub_async.py index ed03fd1ba815..6fb29ab47015 100644 --- a/sdk/eventhub/azure-eventhubs/samples/async_samples/sample_code_eventhub_async.py +++ b/sdk/eventhub/azure-eventhubs/samples/async_samples/sample_code_eventhub_async.py @@ -4,42 +4,65 @@ # license information. #-------------------------------------------------------------------------- -import pytest import logging import asyncio def create_async_eventhub_producer_client(): + # [START create_eventhub_producer_client_from_conn_str_async] + import os + from azure.eventhub.aio import EventHubProducerClient + event_hub_connection_str = os.environ['EVENT_HUB_CONN_STR'] + event_hub = os.environ['EVENT_HUB_NAME'] + producer = EventHubProducerClient.from_connection_string(conn_str=event_hub_connection_str, + event_hub_path=event_hub) + # [END create_eventhub_producer_client_from_conn_str_async] + # [START create_eventhub_producer_client_async] import os + from azure.eventhub import EventHubSharedKeyCredential from azure.eventhub.aio import EventHubProducerClient - EVENT_HUB_CONNECTION_STR = os.environ['EVENT_HUB_CONN_STR'] - EVENT_HUB = os.environ['EVENT_HUB_NAME'] + hostname = os.environ['EVENT_HUB_HOSTNAME'] + event_hub = os.environ['EVENT_HUB_NAME'] + shared_access_policy = os.environ['EVENT_HUB_SAS_POLICY'] + shared_access_key = os.environ['EVENT_HUB_SAS_KEY'] - producer = EventHubProducerClient.from_connection_string(conn_str=EVENT_HUB_CONNECTION_STR, - event_hub_path=EVENT_HUB) + producer = EventHubProducerClient(host=hostname, + event_hub_path=event_hub, + credential=EventHubSharedKeyCredential(shared_access_policy, shared_access_key)) # [END create_eventhub_producer_client_async] return producer def create_async_eventhub_consumer_client(): + # [START create_eventhub_consumer_client_from_conn_str_async] + import os + from azure.eventhub.aio import EventHubConsumerClient + event_hub_connection_str = os.environ['EVENT_HUB_CONN_STR'] + event_hub = os.environ['EVENT_HUB_NAME'] + consumer = EventHubConsumerClient.from_connection_string(conn_str=event_hub_connection_str, + event_hub_path=event_hub) + # [END create_eventhub_consumer_client_from_conn_str_async] + # [START create_eventhub_consumer_client_async] import os + from azure.eventhub import EventHubSharedKeyCredential + from azure.eventhub.aio import EventHubConsumerClient - EVENT_HUB_CONNECTION_STR = os.environ['EVENT_HUB_CONN_STR'] - EVENT_HUB = os.environ['EVENT_HUB_NAME'] + hostname = os.environ['EVENT_HUB_HOSTNAME'] + event_hub = os.environ['EVENT_HUB_NAME'] + shared_access_policy = os.environ['EVENT_HUB_SAS_POLICY'] + shared_access_key = os.environ['EVENT_HUB_SAS_KEY'] - from azure.eventhub.aio import EventHubConsumerClient - consumer = EventHubConsumerClient.from_connection_string( - conn_str=EVENT_HUB_CONNECTION_STR, - event_hub_path=EVENT_HUB - ) + consumer = EventHubConsumerClient(host=hostname, + event_hub_path=event_hub, + credential=EventHubSharedKeyCredential(shared_access_policy, shared_access_key)) # [END create_eventhub_consumer_client_async] return consumer -async def example_eventhub_async_send_and_receive(live_eventhub_config): +async def example_eventhub_async_send_and_receive(): producer = create_async_eventhub_producer_client() consumer = create_async_eventhub_consumer_client() try: @@ -70,25 +93,23 @@ async def on_events(partition_context, events): len(events), partition_context.partition_id)) # Do ops on received events async with consumer: - task = asyncio.ensure_future(consumer.receive(on_events=on_events, consumer_group="$default")) - await asyncio.sleep(3) # keep receiving for 3 seconds - task.cancel() # stop receiving + await consumer.receive(on_events=on_events, consumer_group="$default") # [END eventhub_consumer_client_receive_async] finally: pass -async def example_eventhub_async_producer_ops(live_eventhub_config, connection_str): +async def example_eventhub_async_producer_ops(): # [START eventhub_producer_client_close_async] import os from azure.eventhub.aio import EventHubProducerClient from azure.eventhub import EventData - EVENT_HUB_CONNECTION_STR = os.environ['EVENT_HUB_CONN_STR'] - EVENT_HUB = os.environ['EVENT_HUB_NAME'] + event_hub_connection_str = os.environ['EVENT_HUB_CONN_STR'] + event_hub = os.environ['EVENT_HUB_NAME'] - producer = EventHubProducerClient.from_connection_string(conn_str=EVENT_HUB_CONNECTION_STR, - event_hub_path=EVENT_HUB) + producer = EventHubProducerClient.from_connection_string(conn_str=event_hub_connection_str, + event_hub_path=event_hub) try: await producer.send(EventData(b"A single event")) finally: @@ -97,17 +118,17 @@ async def example_eventhub_async_producer_ops(live_eventhub_config, connection_s # [END eventhub_producer_client_close_async] -async def example_eventhub_async_consumer_ops(live_eventhub_config, connection_str): +async def example_eventhub_async_consumer_ops(): # [START eventhub_consumer_client_close_async] import os - EVENT_HUB_CONNECTION_STR = os.environ['EVENT_HUB_CONN_STR'] - EVENT_HUB = os.environ['EVENT_HUB_NAME'] + event_hub_connection_str = os.environ['EVENT_HUB_CONN_STR'] + event_hub = os.environ['EVENT_HUB_NAME'] from azure.eventhub.aio import EventHubConsumerClient consumer = EventHubConsumerClient.from_connection_string( - conn_str=EVENT_HUB_CONNECTION_STR, - event_hub_path=EVENT_HUB + conn_str=event_hub_connection_str, + event_hub_path=event_hub ) logger = logging.getLogger("azure.eventhub") @@ -127,3 +148,9 @@ async def on_events(partition_context, events): # Close down the consumer handler explicitly. await consumer.close() # [END eventhub_consumer_client_close_async] + +if __name__ == '__main__': + loop = asyncio.get_event_loop() + loop.run_until_complete(example_eventhub_async_producer_ops()) + loop.run_until_complete(example_eventhub_async_consumer_ops()) + # loop.run_until_complete(example_eventhub_async_send_and_receive()) 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 8c1eaa9de893..5869060be95e 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 @@ -9,31 +9,53 @@ def create_eventhub_producer_client(): - # [START create_eventhub_producer_client_sync] + # [START create_eventhub_producer_client_from_conn_str_sync] import os from azure.eventhub import EventHubProducerClient + event_hub_connection_str = os.environ['EVENT_HUB_CONN_STR'] + event_hub = os.environ['EVENT_HUB_NAME'] + producer = EventHubProducerClient.from_connection_string(conn_str=event_hub_connection_str, + event_hub_path=event_hub) + # [END create_eventhub_producer_client_from_conn_str_sync] - EVENT_HUB_CONNECTION_STR = os.environ['EVENT_HUB_CONN_STR'] - EVENT_HUB = os.environ['EVENT_HUB_NAME'] + # [START create_eventhub_producer_client_sync] + import os + from azure.eventhub import EventHubProducerClient, EventHubSharedKeyCredential - producer = EventHubProducerClient.from_connection_string(conn_str=EVENT_HUB_CONNECTION_STR, - event_hub_path=EVENT_HUB) + hostname = os.environ['EVENT_HUB_HOSTNAME'] + event_hub = os.environ['EVENT_HUB_NAME'] + shared_access_policy = os.environ['EVENT_HUB_SAS_POLICY'] + shared_access_key = os.environ['EVENT_HUB_SAS_KEY'] + + producer = EventHubProducerClient(host=hostname, + event_hub_path=event_hub, + credential=EventHubSharedKeyCredential(shared_access_policy, shared_access_key)) # [END create_eventhub_producer_client_sync] return producer def create_eventhub_consumer_client(): + # [START create_eventhub_consumer_client_from_conn_str_sync] + import os + from azure.eventhub import EventHubConsumerClient + event_hub_connection_str = os.environ['EVENT_HUB_CONN_STR'] + event_hub = os.environ['EVENT_HUB_NAME'] + consumer = EventHubConsumerClient.from_connection_string(conn_str=event_hub_connection_str, + event_hub_path=event_hub) + # [END create_eventhub_consumer_client_from_conn_str_sync] + # [START create_eventhub_consumer_client_sync] import os + from azure.eventhub import EventHubConsumerClient, EventHubSharedKeyCredential - EVENT_HUB_CONNECTION_STR = os.environ['EVENT_HUB_CONN_STR'] - EVENT_HUB = os.environ['EVENT_HUB_NAME'] + hostname = os.environ['EVENT_HUB_HOSTNAME'] + event_hub = os.environ['EVENT_HUB_NAME'] + shared_access_policy = os.environ['EVENT_HUB_SAS_POLICY'] + shared_access_key = os.environ['EVENT_HUB_SAS_KEY'] - from azure.eventhub import EventHubConsumerClient - consumer = EventHubConsumerClient.from_connection_string( - conn_str=EVENT_HUB_CONNECTION_STR, - event_hub_path=EVENT_HUB - ) + consumer = EventHubConsumerClient(host=hostname, + event_hub_path=event_hub, + credential=EventHubSharedKeyCredential(shared_access_policy, shared_access_key)) # [END create_eventhub_consumer_client_sync] return consumer @@ -93,11 +115,11 @@ def example_eventhub_producer_ops(): import os from azure.eventhub import EventHubProducerClient, EventData - EVENT_HUB_CONNECTION_STR = os.environ['EVENT_HUB_CONN_STR'] - EVENT_HUB = os.environ['EVENT_HUB_NAME'] + event_hub_connection_str = os.environ['EVENT_HUB_CONN_STR'] + event_hub = os.environ['EVENT_HUB_NAME'] - producer = EventHubProducerClient.from_connection_string(conn_str=EVENT_HUB_CONNECTION_STR, - event_hub_path=EVENT_HUB) + producer = EventHubProducerClient.from_connection_string(conn_str=event_hub_connection_str, + event_hub_path=event_hub) try: producer.send(EventData(b"A single event")) finally: @@ -111,13 +133,13 @@ def example_eventhub_consumer_ops(): import os import threading - EVENT_HUB_CONNECTION_STR = os.environ['EVENT_HUB_CONN_STR'] - EVENT_HUB = os.environ['EVENT_HUB_NAME'] + event_hub_connection_str = os.environ['EVENT_HUB_CONN_STR'] + event_hub = os.environ['EVENT_HUB_NAME'] from azure.eventhub import EventHubConsumerClient consumer = EventHubConsumerClient.from_connection_string( - conn_str=EVENT_HUB_CONNECTION_STR, - event_hub_path=EVENT_HUB + conn_str=event_hub_connection_str, + event_hub_path=event_hub ) logger = logging.getLogger("azure.eventhub")