Skip to content

Commit 3af58d0

Browse files
authored
Update from connection string and test.yml (#8392)
* update env name in yml * update from connection string * small fix
1 parent f226bed commit 3af58d0

File tree

5 files changed

+122
-3
lines changed

5 files changed

+122
-3
lines changed

sdk/eventhub/azure-eventhubs/azure/eventhub/_consumer_client.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,39 @@ def _stop_eventprocessor(cls, event_processor):
9696
elif (consumer_group, '-1') in eventhub_client._event_processors:
9797
del eventhub_client._event_processors[(consumer_group, "-1")]
9898

99+
@classmethod
100+
def from_connection_string(cls, conn_str, **kwargs):
101+
"""
102+
Create an EventHubConsumerClient from a connection string.
103+
104+
:param str conn_str: The connection string of an eventhub.
105+
:keyword str event_hub_path: The path of the specific Event Hub to connect the client to.
106+
:keyword credential: The credential object used for authentication which implements particular interface
107+
of getting tokens. It accepts ~azure.eventhub.EventHubSharedKeyCredential,
108+
~azure.eventhub.EventHubSASTokenCredential, credential objects generated by the azure-identity library and
109+
objects that implement `get_token(self, *scopes)` method.
110+
:keyword bool network_tracing: Whether to output network trace logs to the logger. Default is `False`.
111+
:keyword dict[str, Any] http_proxy: HTTP proxy settings. This must be a dictionary with the following
112+
keys - 'proxy_hostname' (str value) and 'proxy_port' (int value).
113+
Additionally the following keys may also be present - 'username', 'password'.
114+
:keyword float auth_timeout: The time in seconds to wait for a token to be authorized by the service.
115+
The default value is 60 seconds. If set to 0, no timeout will be enforced from the client.
116+
:keyword str user_agent: The user agent that needs to be appended to the built in user agent string.
117+
:keyword int retry_total: The total number of attempts to redo the failed operation when an error happened.
118+
Default value is 3.
119+
:keyword transport_type: The type of transport protocol that will be used for communicating with
120+
the Event Hubs service. Default is `TransportType.Amqp`.
121+
:paramtype transport_type: ~azure.eventhub.TransportType
122+
:keyword partition_manager:
123+
stores the load balancing data and checkpoint data when receiving events
124+
if partition_manager is specified. If it's None, this EventHubConsumerClient instance will receive
125+
events without load balancing and checkpoint.
126+
:paramtype partition_manager: Implementation classes of ~azure.eventhub.aio.PartitionManager
127+
:keyword float load_balancing_interval:
128+
When load balancing kicks in, this is the interval in seconds between two load balancing. Default is 10.
129+
"""
130+
return super(EventHubConsumerClient, cls).from_connection_string(conn_str, **kwargs)
131+
99132
def receive(self, on_events, consumer_group, **kwargs):
100133
# type: (Callable[[PartitionContext, List[EventData]], None], str, Any) -> None
101134
"""Receive events from partition(s) optionally with load balancing and checkpointing.

sdk/eventhub/azure-eventhubs/azure/eventhub/_producer_client.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,32 @@ def _init_locks_for_producers(self):
7171
for _ in range(num_of_producers):
7272
self._producers_locks.append(threading.Lock())
7373

74+
@classmethod
75+
def from_connection_string(cls, conn_str, **kwargs):
76+
"""
77+
Create an EventHubProducerClient from a connection string.
78+
79+
:param str conn_str: The connection string of an eventhub.
80+
:keyword str event_hub_path: The path of the specific Event Hub to connect the client to.
81+
:keyword credential: The credential object used for authentication which implements particular interface
82+
of getting tokens. It accepts ~azure.eventhub.EventHubSharedKeyCredential,
83+
~azure.eventhub.EventHubSASTokenCredential, credential objects generated by the azure-identity library and
84+
objects that implement `get_token(self, *scopes)` method.
85+
:keyword bool network_tracing: Whether to output network trace logs to the logger. Default is `False`.
86+
:keyword dict[str, Any] http_proxy: HTTP proxy settings. This must be a dictionary with the following
87+
keys - 'proxy_hostname' (str value) and 'proxy_port' (int value).
88+
Additionally the following keys may also be present - 'username', 'password'.
89+
:keyword float auth_timeout: The time in seconds to wait for a token to be authorized by the service.
90+
The default value is 60 seconds. If set to 0, no timeout will be enforced from the client.
91+
:keyword str user_agent: The user agent that needs to be appended to the built in user agent string.
92+
:keyword int retry_total: The total number of attempts to redo the failed operation when an error happened.
93+
Default value is 3.
94+
:keyword transport_type: The type of transport protocol that will be used for communicating with
95+
the Event Hubs service. Default is `TransportType.Amqp`.
96+
:paramtype transport_type: ~azure.eventhub.TransportType
97+
"""
98+
return super(EventHubProducerClient, cls).from_connection_string(conn_str, **kwargs)
99+
74100
def send(self, event_data, **kwargs):
75101
# type: (Union[EventData, EventDataBatch, Iterable[EventData]], Any) -> None
76102
"""

sdk/eventhub/azure-eventhubs/azure/eventhub/aio/_consumer_client_async.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,39 @@ def __init__(self, host, event_hub_path, credential, **kwargs) -> None:
7676
self._event_processors = dict() # type: Dict[Tuple[str, str], EventProcessor]
7777
self._closed = False
7878

79+
@classmethod
80+
def from_connection_string(cls, conn_str, **kwargs):
81+
"""
82+
Create an EventHubConsumerClient from a connection string.
83+
84+
:param str conn_str: The connection string of an eventhub.
85+
:keyword str event_hub_path: The path of the specific Event Hub to connect the client to.
86+
:keyword credential: The credential object used for authentication which implements particular interface
87+
of getting tokens. It accepts ~azure.eventhub.EventHubSharedKeyCredential,
88+
~azure.eventhub.EventHubSASTokenCredential, credential objects generated by the azure-identity library and
89+
objects that implement `get_token(self, *scopes)` method.
90+
:keyword bool network_tracing: Whether to output network trace logs to the logger. Default is `False`.
91+
:keyword dict[str, Any] http_proxy: HTTP proxy settings. This must be a dictionary with the following
92+
keys - 'proxy_hostname' (str value) and 'proxy_port' (int value).
93+
Additionally the following keys may also be present - 'username', 'password'.
94+
:keyword float auth_timeout: The time in seconds to wait for a token to be authorized by the service.
95+
The default value is 60 seconds. If set to 0, no timeout will be enforced from the client.
96+
:keyword str user_agent: The user agent that needs to be appended to the built in user agent string.
97+
:keyword int retry_total: The total number of attempts to redo the failed operation when an error happened.
98+
Default value is 3.
99+
:keyword transport_type: The type of transport protocol that will be used for communicating with
100+
the Event Hubs service. Default is `TransportType.Amqp`.
101+
:paramtype transport_type: ~azure.eventhub.TransportType
102+
:keyword partition_manager:
103+
stores the load balancing data and checkpoint data when receiving events
104+
if partition_manager is specified. If it's None, this EventHubConsumerClient instance will receive
105+
events without load balancing and checkpoint.
106+
:paramtype partition_manager: Implementation classes of ~azure.eventhub.aio.PartitionManager
107+
:keyword float load_balancing_interval:
108+
When load balancing kicks in, this is the interval in seconds between two load balancing. Default is 10.
109+
"""
110+
return super(EventHubConsumerClient, cls).from_connection_string(conn_str, **kwargs)
111+
79112
async def receive(
80113
self, on_events, consumer_group: str,
81114
*,

sdk/eventhub/azure-eventhubs/azure/eventhub/aio/_producer_client_async.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,32 @@ async def _init_locks_for_producers(self):
7171
self._producers_locks.append(asyncio.Lock())
7272
# self._producers_locks = [asyncio.Lock()] * num_of_producers
7373

74+
@classmethod
75+
def from_connection_string(cls, conn_str, **kwargs):
76+
"""
77+
Create an EventHubProducerClient from a connection string.
78+
79+
:param str conn_str: The connection string of an eventhub.
80+
:keyword str event_hub_path: The path of the specific Event Hub to connect the client to.
81+
:keyword credential: The credential object used for authentication which implements particular interface
82+
of getting tokens. It accepts ~azure.eventhub.EventHubSharedKeyCredential,
83+
~azure.eventhub.EventHubSASTokenCredential, credential objects generated by the azure-identity library and
84+
objects that implement `get_token(self, *scopes)` method.
85+
:keyword bool network_tracing: Whether to output network trace logs to the logger. Default is `False`.
86+
:keyword dict[str, Any] http_proxy: HTTP proxy settings. This must be a dictionary with the following
87+
keys - 'proxy_hostname' (str value) and 'proxy_port' (int value).
88+
Additionally the following keys may also be present - 'username', 'password'.
89+
:keyword float auth_timeout: The time in seconds to wait for a token to be authorized by the service.
90+
The default value is 60 seconds. If set to 0, no timeout will be enforced from the client.
91+
:keyword str user_agent: The user agent that needs to be appended to the built in user agent string.
92+
:keyword int retry_total: The total number of attempts to redo the failed operation when an error happened.
93+
Default value is 3.
94+
:keyword transport_type: The type of transport protocol that will be used for communicating with
95+
the Event Hubs service. Default is `TransportType.Amqp`.
96+
:paramtype transport_type: ~azure.eventhub.TransportType
97+
"""
98+
return super(EventHubProducerClient, cls).from_connection_string(conn_str, **kwargs)
99+
74100
async def send(self, event_data,
75101
*, partition_key: Union[str, bytes] = None, partition_id: str = None, timeout: float = None) -> None:
76102
"""Sends event data and blocks until acknowledgement is received or operation times out.

sdk/eventhub/tests.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,14 @@ jobs:
2828
AZURE_STORAGE_ACCOUNT: $(python-eh-livetest-event-hub-storage-account)
2929
AZURE_STORAGE_ACCESS_KEY: $(python-eh-livetest-event-hub-storage-access-key)
3030
AZURE_STORAGE_CONN_STR: $(python-eh-livetest-event-hub-storage-conn-str)
31+
EVENT_HUB_CONN_STR: $(python-eh-livetest-event-hub-conn-str)
3132
EVENT_HUB_HOSTNAME: $(python-eh-livetest-event-hub-hostname)
3233
EVENT_HUB_NAME: $(python-eh-livetest-event-hub-name)
3334
EVENT_HUB_SAS_POLICY: $(python-eh-livetest-event-hub-sas-policy)
3435
EVENT_HUB_SAS_KEY: $(python-eh-livetest-event-hub-sas-key)
3536
EVENT_HUB_NAMESPACE: $(python-eh-livetest-event-hub-namespace)
3637
IOTHUB_CONNECTION_STR: $(python-eh-livetest-event-hub-iothub-connection-str)
3738
IOTHUB_DEVICE: $(python-eh-livetest-event-hub-iothub-device)
38-
AAD_CLIENT_ID: $(python-eh-livetest-event-hub-aad-client-id)
39-
AAD_TENANT_ID: $(python-eh-livetest-event-hub-aad-tenant-id)
40-
AAD_SECRET: $(python-eh-livetest-event-hub-aad-secret)
39+
AZURE_CLIENT_ID: $(python-eh-livetest-event-hub-aad-client-id)
40+
AZURE_TENANT_ID: $(python-eh-livetest-event-hub-aad-tenant-id)
41+
AZURE_CLIENT_SECRET: $(python-eh-livetest-event-hub-aad-secret)

0 commit comments

Comments
 (0)