From 541c559b0ba06cd100097249b28a2144c3b68f42 Mon Sep 17 00:00:00 2001 From: l0lawrence Date: Tue, 24 May 2022 09:08:44 -0700 Subject: [PATCH 01/10] starting to add ce capability for sync --- .../servicebus/_common/_configuration.py | 24 ++++++++++++- .../azure/servicebus/_servicebus_client.py | 28 +++++++++++++++ .../connection_to_custom_endpoint.py | 35 +++++++++++++++++++ 3 files changed, 86 insertions(+), 1 deletion(-) create mode 100644 sdk/servicebus/azure-servicebus/samples/sync_samples/connection_to_custom_endpoint.py diff --git a/sdk/servicebus/azure-servicebus/azure/servicebus/_common/_configuration.py b/sdk/servicebus/azure-servicebus/azure/servicebus/_common/_configuration.py index 7eb6de1017b3..7129b1293a9d 100644 --- a/sdk/servicebus/azure-servicebus/azure/servicebus/_common/_configuration.py +++ b/sdk/servicebus/azure-servicebus/azure/servicebus/_common/_configuration.py @@ -3,8 +3,9 @@ # Licensed under the MIT License. See License.txt in the project root for license information. # -------------------------------------------------------------------------------------------- from typing import Optional, Dict, Any +from urllib.parse import urlparse -from uamqp.constants import TransportType +from uamqp.constants import TransportType, DEFAULT_AMQP_WSS_PORT, DEFAULT_AMQPS_PORT from azure.core.pipeline.policies import RetryMode @@ -30,3 +31,24 @@ def __init__(self, **kwargs): self.auto_reconnect = kwargs.get("auto_reconnect", True) self.keep_alive = kwargs.get("keep_alive", 30) self.timeout = kwargs.get("timeout", 60) # type: float + + self.custom_endpoint_address = kwargs.get("custom_endpoint_address") # type: Optional[str] + self.connection_verify = kwargs.get("connection_verify") # type: Optional[str] + self.connection_port = DEFAULT_AMQPS_PORT + self.custom_endpoint_hostname = None + + if self.http_proxy or self.transport_type == TransportType.AmqpOverWebsocket: + self.transport_type = TransportType.AmqpOverWebsocket + self.connection_port = DEFAULT_AMQP_WSS_PORT + + # custom end point + if self.custom_endpoint_address: + # if the custom_endpoint_address doesn't include the schema, + # we prepend a default one to make urlparse work + if self.custom_endpoint_address.find("//") == -1: + self.custom_endpoint_address = "sb://" + self.custom_endpoint_address + endpoint = urlparse(self.custom_endpoint_address) + self.transport_type = TransportType.AmqpOverWebsocket + self.custom_endpoint_hostname = endpoint.hostname + # in case proxy and custom endpoint are both provided, we default port to 443 if it's not provided + self.connection_port = endpoint.port or DEFAULT_AMQP_WSS_PORT diff --git a/sdk/servicebus/azure-servicebus/azure/servicebus/_servicebus_client.py b/sdk/servicebus/azure-servicebus/azure/servicebus/_servicebus_client.py index b8804ffdb8cd..60724fe65067 100644 --- a/sdk/servicebus/azure-servicebus/azure/servicebus/_servicebus_client.py +++ b/sdk/servicebus/azure-servicebus/azure/servicebus/_servicebus_client.py @@ -76,6 +76,14 @@ class ServiceBusClient(object): # pylint: disable=client-accepts-api-version-key :keyword retry_mode: The delay behavior between retry attempts. Supported values are "fixed" or "exponential", where default is "exponential". :paramtype retry_mode: str + :keyword str custom_endpoint_address: The custom endpoint address to use for establishing a connection to + the Event Hubs service, allowing network requests to be routed through any application gateways or + other paths needed for the host environment. Default is None. + The format would be like "sb://:". + If port is not specified in the `custom_endpoint_address`, by default port 443 will be used. + :keyword str connection_verify: Path to the custom CA_BUNDLE file of the SSL certificate which is used to + authenticate the identity of the connection endpoint. + Default is None in which case `certifi.where()` will be used. .. admonition:: Example: @@ -196,6 +204,14 @@ def from_connection_string( :keyword retry_mode: The delay behavior between retry attempts. Supported values are 'fixed' or 'exponential', where default is 'exponential'. :paramtype retry_mode: str + :keyword str custom_endpoint_address: The custom endpoint address to use for establishing a connection to + the Event Hubs service, allowing network requests to be routed through any application gateways or + other paths needed for the host environment. Default is None. + The format would be like "sb://:". + If port is not specified in the custom_endpoint_address, by default port 443 will be used. + :keyword str connection_verify: Path to the custom CA_BUNDLE file of the SSL certificate which is used to + authenticate the identity of the connection endpoint. + Default is None in which case `certifi.where()` will be used. :rtype: ~azure.servicebus.ServiceBusClient .. admonition:: Example: @@ -264,6 +280,9 @@ def get_queue_sender(self, queue_name, **kwargs): retry_total=self._config.retry_total, retry_backoff_factor=self._config.retry_backoff_factor, retry_backoff_max=self._config.retry_backoff_max, + custom_endpoint_hostname=self._config.custom_endpoint_hostname, + port=self._config.connection_port, + verify=self._config.connection_verify, **kwargs ) self._handlers.add(handler) @@ -415,6 +434,9 @@ def get_topic_sender(self, topic_name, **kwargs): retry_total=self._config.retry_total, retry_backoff_factor=self._config.retry_backoff_factor, retry_backoff_max=self._config.retry_backoff_max, + custom_endpoint_hostname=self._config.custom_endpoint_hostname, + port=self._config.connection_port, + verify=self._config.connection_verify, **kwargs ) self._handlers.add(handler) @@ -523,6 +545,9 @@ def get_subscription_receiver( max_wait_time=max_wait_time, auto_lock_renewer=auto_lock_renewer, prefetch_count=prefetch_count, + custom_endpoint_hostname=self._config.custom_endpoint_hostname, + port=self._config.connection_port, + verify=self._config.connection_verify, **kwargs ) except ValueError: @@ -550,6 +575,9 @@ def get_subscription_receiver( max_wait_time=max_wait_time, auto_lock_renewer=auto_lock_renewer, prefetch_count=prefetch_count, + custom_endpoint_hostname=self._config.custom_endpoint_hostname, + port=self._config.connection_port, + verify=self._config.connection_verify, **kwargs ) self._handlers.add(handler) diff --git a/sdk/servicebus/azure-servicebus/samples/sync_samples/connection_to_custom_endpoint.py b/sdk/servicebus/azure-servicebus/samples/sync_samples/connection_to_custom_endpoint.py new file mode 100644 index 000000000000..2b20246a0d24 --- /dev/null +++ b/sdk/servicebus/azure-servicebus/samples/sync_samples/connection_to_custom_endpoint.py @@ -0,0 +1,35 @@ +#!/usr/bin/env python + +# -------------------------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +# -------------------------------------------------------------------------------------------- + +""" +Examples to show how to create async EventHubProducerClient and EventHubConsumerClient that connect to custom endpoint. +""" + +import os +from azure.servicebus import ServiceBusClient, ServiceBusMessage + + +CONNECTION_STR = os.environ['SERVICE_BUS_CONNECTION_STR'] +QUEUE_NAME = os.environ["SERVICE_BUS_QUEUE_NAME"] +# The custom endpoint address to use for establishing a connection to the Service Bus service, +# allowing network requests to be routed through any application gateways +# or other paths needed for the host environment. +CUSTOM_ENDPOINT_ADDRESS = 'sb://:' +# The optional absolute path to the custom certificate file used by client to authenticate the +# identity of the connection endpoint in the case that endpoint has its own issued CA. +# If not set, the certifi library will be used to load certificates. +CUSTOM_CA_BUNDLE_PATH = '' + +def send_single_message(sender): + message = ServiceBusMessage("Single Message") + sender.send_messages(message) + +servicebus_client = ServiceBusClient.from_connection_string(conn_str=CONNECTION_STR, logging_enable=True) +with servicebus_client: + sender = servicebus_client.get_queue_sender(queue_name=QUEUE_NAME) + with sender: + send_single_message(sender) From b765db3a3ff6fef99dc351d02cd77d0e0246808a Mon Sep 17 00:00:00 2001 From: l0lawrence Date: Tue, 24 May 2022 10:21:42 -0700 Subject: [PATCH 02/10] sync ce pass through --- .../azure/servicebus/_common/utils.py | 6 +++++ .../azure/servicebus/_servicebus_client.py | 25 ++++++++++--------- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/sdk/servicebus/azure-servicebus/azure/servicebus/_common/utils.py b/sdk/servicebus/azure-servicebus/azure/servicebus/_common/utils.py index 8c2783d96bd3..96e10df347c2 100644 --- a/sdk/servicebus/azure-servicebus/azure/servicebus/_common/utils.py +++ b/sdk/servicebus/azure-servicebus/azure/servicebus/_common/utils.py @@ -173,6 +173,9 @@ def create_authentication(client): timeout=client._config.auth_timeout, http_proxy=client._config.http_proxy, transport_type=client._config.transport_type, + custom_endpoint_hostname=client._config.custom_endpoint_hostname, + port=client._config.connection_port, + verify=client._config.connection_verify ) auth.update_token() return auth @@ -185,6 +188,9 @@ def create_authentication(client): http_proxy=client._config.http_proxy, transport_type=client._config.transport_type, refresh_window=300, + custom_endpoint_hostname=client._config.custom_endpoint_hostname, + port=client._config.connection_port, + verify=client._config.connection_verify ) diff --git a/sdk/servicebus/azure-servicebus/azure/servicebus/_servicebus_client.py b/sdk/servicebus/azure-servicebus/azure/servicebus/_servicebus_client.py index 60724fe65067..603ddb480a07 100644 --- a/sdk/servicebus/azure-servicebus/azure/servicebus/_servicebus_client.py +++ b/sdk/servicebus/azure-servicebus/azure/servicebus/_servicebus_client.py @@ -132,6 +132,9 @@ def __init__( self._connection_sharing = False self._handlers = WeakSet() # type: WeakSet + self._custom_endpoint_address = kwargs.get('custom_endpoint_address') + self._connection_verify = kwargs.get("connection_verify") + def __enter__(self): if self._connection_sharing: self._create_uamqp_connection() @@ -280,9 +283,8 @@ def get_queue_sender(self, queue_name, **kwargs): retry_total=self._config.retry_total, retry_backoff_factor=self._config.retry_backoff_factor, retry_backoff_max=self._config.retry_backoff_max, - custom_endpoint_hostname=self._config.custom_endpoint_hostname, - port=self._config.connection_port, - verify=self._config.connection_verify, + custom_endpoint_address=self._custom_endpoint_address, + connection_verify=self._connection_verify, **kwargs ) self._handlers.add(handler) @@ -392,6 +394,8 @@ def get_queue_receiver( max_wait_time=max_wait_time, auto_lock_renewer=auto_lock_renewer, prefetch_count=prefetch_count, + custom_endpoint_address=self._custom_endpoint_address, + connection_verify=self._connection_verify, **kwargs ) self._handlers.add(handler) @@ -434,9 +438,8 @@ def get_topic_sender(self, topic_name, **kwargs): retry_total=self._config.retry_total, retry_backoff_factor=self._config.retry_backoff_factor, retry_backoff_max=self._config.retry_backoff_max, - custom_endpoint_hostname=self._config.custom_endpoint_hostname, - port=self._config.connection_port, - verify=self._config.connection_verify, + custom_endpoint_address=self._custom_endpoint_address, + connection_verify=self._connection_verify, **kwargs ) self._handlers.add(handler) @@ -545,9 +548,8 @@ def get_subscription_receiver( max_wait_time=max_wait_time, auto_lock_renewer=auto_lock_renewer, prefetch_count=prefetch_count, - custom_endpoint_hostname=self._config.custom_endpoint_hostname, - port=self._config.connection_port, - verify=self._config.connection_verify, + custom_endpoint_address=self._custom_endpoint_address, + connection_verify=self._connection_verify, **kwargs ) except ValueError: @@ -575,9 +577,8 @@ def get_subscription_receiver( max_wait_time=max_wait_time, auto_lock_renewer=auto_lock_renewer, prefetch_count=prefetch_count, - custom_endpoint_hostname=self._config.custom_endpoint_hostname, - port=self._config.connection_port, - verify=self._config.connection_verify, + custom_endpoint_address=self._custom_endpoint_address, + connection_verify=self._connection_verify, **kwargs ) self._handlers.add(handler) From 0f86257de1f9514f3fbf5c076aa952fd0e5e8537 Mon Sep 17 00:00:00 2001 From: l0lawrence Date: Tue, 24 May 2022 14:28:18 -0700 Subject: [PATCH 03/10] add ce async --- .../servicebus/aio/_servicebus_client_async.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/sdk/servicebus/azure-servicebus/azure/servicebus/aio/_servicebus_client_async.py b/sdk/servicebus/azure-servicebus/azure/servicebus/aio/_servicebus_client_async.py index c601d92d68f2..8f70f6cb4920 100644 --- a/sdk/servicebus/azure-servicebus/azure/servicebus/aio/_servicebus_client_async.py +++ b/sdk/servicebus/azure-servicebus/azure/servicebus/aio/_servicebus_client_async.py @@ -116,6 +116,9 @@ def __init__( self._connection_sharing = False self._handlers = WeakSet() # type: WeakSet + self._custom_endpoint_address = kwargs.get("custom_endpoint_address") + self._connection_verify = kwargs.get("connection_verify") + async def __aenter__(self): if self._connection_sharing: await self._create_uamqp_connection() @@ -253,6 +256,8 @@ def get_queue_sender(self, queue_name: str, **kwargs: Any) -> ServiceBusSender: retry_total=self._config.retry_total, retry_backoff_factor=self._config.retry_backoff_factor, retry_backoff_max=self._config.retry_backoff_max, + custom_endpoint_address=self._custom_endpoint_address, + connection_verify=self._connection_verify, **kwargs ) self._handlers.add(handler) @@ -361,6 +366,8 @@ def get_queue_receiver( max_wait_time=max_wait_time, auto_lock_renewer=auto_lock_renewer, prefetch_count=prefetch_count, + custom_endpoint_address=self._custom_endpoint_address, + connection_verify=self._connection_verify, **kwargs ) self._handlers.add(handler) @@ -402,6 +409,8 @@ def get_topic_sender(self, topic_name: str, **kwargs: Any) -> ServiceBusSender: retry_total=self._config.retry_total, retry_backoff_factor=self._config.retry_backoff_factor, retry_backoff_max=self._config.retry_backoff_max, + custom_endpoint_address=self._custom_endpoint_address, + connection_verify=self._connection_verify, **kwargs ) self._handlers.add(handler) @@ -510,6 +519,8 @@ def get_subscription_receiver( max_wait_time=max_wait_time, auto_lock_renewer=auto_lock_renewer, prefetch_count=prefetch_count, + custom_endpoint_address=self._custom_endpoint_address, + connection_verify=self._connection_verify, **kwargs ) except ValueError: @@ -537,6 +548,8 @@ def get_subscription_receiver( max_wait_time=max_wait_time, auto_lock_renewer=auto_lock_renewer, prefetch_count=prefetch_count, + custom_endpoint_address=self._custom_endpoint_address, + connection_verify=self._connection_verify, **kwargs ) self._handlers.add(handler) From 5011848aba05ae76443c2ae0800833ccc689701f Mon Sep 17 00:00:00 2001 From: l0lawrence Date: Tue, 24 May 2022 14:34:46 -0700 Subject: [PATCH 04/10] async test --- ...ection_to_custom_endpoint_address_async.py | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 sdk/servicebus/azure-servicebus/samples/async_samples/connection_to_custom_endpoint_address_async.py diff --git a/sdk/servicebus/azure-servicebus/samples/async_samples/connection_to_custom_endpoint_address_async.py b/sdk/servicebus/azure-servicebus/samples/async_samples/connection_to_custom_endpoint_address_async.py new file mode 100644 index 000000000000..c13a55520dcf --- /dev/null +++ b/sdk/servicebus/azure-servicebus/samples/async_samples/connection_to_custom_endpoint_address_async.py @@ -0,0 +1,47 @@ +#!/usr/bin/env python + +# -------------------------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +# -------------------------------------------------------------------------------------------- + +""" +Examples to show how to create async EventHubProducerClient and EventHubConsumerClient that connect to custom endpoint. +""" + +import os +import asyncio +from azure.servicebus import ServiceBusMessage +from azure.servicebus.aio import ServiceBusClient + + +CONNECTION_STR = os.environ['SERVICE_BUS_CONNECTION_STR'] +QUEUE_NAME = os.environ["SERVICE_BUS_QUEUE_NAME"] +# The custom endpoint address to use for establishing a connection to the Service Bus service, +# allowing network requests to be routed through any application gateways +# or other paths needed for the host environment. +CUSTOM_ENDPOINT_ADDRESS = 'sb://:' +# The optional absolute path to the custom certificate file used by client to authenticate the +# identity of the connection endpoint in the case that endpoint has its own issued CA. +# If not set, the certifi library will be used to load certificates. +CUSTOM_CA_BUNDLE_PATH = '' + +async def send_single_message(sender): + message = ServiceBusMessage("Single Message") + sender.send_messages(message) + +async def main(): + servicebus_client = ServiceBusClient.from_connection_string( + conn_str=CONNECTION_STR, + custom_endpoint_address=CUSTOM_ENDPOINT_ADDRESS, + connection_verify=CUSTOM_CA_BUNDLE_PATH + ) + async with servicebus_client: + sender = servicebus_client.get_queue_sender(queue_name=QUEUE_NAME) + async with sender: + await send_single_message(sender) + print("Send message is done.") + + +asyncio.run(main()) + From e51a1186c199675a83cee2c8b694e04732c6eca4 Mon Sep 17 00:00:00 2001 From: l0lawrence Date: Tue, 24 May 2022 14:35:29 -0700 Subject: [PATCH 05/10] update sync test --- .../connection_to_custom_endpoint.py | 35 ------------------- 1 file changed, 35 deletions(-) delete mode 100644 sdk/servicebus/azure-servicebus/samples/sync_samples/connection_to_custom_endpoint.py diff --git a/sdk/servicebus/azure-servicebus/samples/sync_samples/connection_to_custom_endpoint.py b/sdk/servicebus/azure-servicebus/samples/sync_samples/connection_to_custom_endpoint.py deleted file mode 100644 index 2b20246a0d24..000000000000 --- a/sdk/servicebus/azure-servicebus/samples/sync_samples/connection_to_custom_endpoint.py +++ /dev/null @@ -1,35 +0,0 @@ -#!/usr/bin/env python - -# -------------------------------------------------------------------------------------------- -# Copyright (c) Microsoft Corporation. All rights reserved. -# Licensed under the MIT License. See License.txt in the project root for license information. -# -------------------------------------------------------------------------------------------- - -""" -Examples to show how to create async EventHubProducerClient and EventHubConsumerClient that connect to custom endpoint. -""" - -import os -from azure.servicebus import ServiceBusClient, ServiceBusMessage - - -CONNECTION_STR = os.environ['SERVICE_BUS_CONNECTION_STR'] -QUEUE_NAME = os.environ["SERVICE_BUS_QUEUE_NAME"] -# The custom endpoint address to use for establishing a connection to the Service Bus service, -# allowing network requests to be routed through any application gateways -# or other paths needed for the host environment. -CUSTOM_ENDPOINT_ADDRESS = 'sb://:' -# The optional absolute path to the custom certificate file used by client to authenticate the -# identity of the connection endpoint in the case that endpoint has its own issued CA. -# If not set, the certifi library will be used to load certificates. -CUSTOM_CA_BUNDLE_PATH = '' - -def send_single_message(sender): - message = ServiceBusMessage("Single Message") - sender.send_messages(message) - -servicebus_client = ServiceBusClient.from_connection_string(conn_str=CONNECTION_STR, logging_enable=True) -with servicebus_client: - sender = servicebus_client.get_queue_sender(queue_name=QUEUE_NAME) - with sender: - send_single_message(sender) From 481e851762f944d5493e92a466309709b8a86901 Mon Sep 17 00:00:00 2001 From: l0lawrence Date: Tue, 24 May 2022 14:36:03 -0700 Subject: [PATCH 06/10] update sync test --- .../connection_to_custom_endpoint_address.py | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 sdk/servicebus/azure-servicebus/samples/sync_samples/connection_to_custom_endpoint_address.py diff --git a/sdk/servicebus/azure-servicebus/samples/sync_samples/connection_to_custom_endpoint_address.py b/sdk/servicebus/azure-servicebus/samples/sync_samples/connection_to_custom_endpoint_address.py new file mode 100644 index 000000000000..e27b9e20be6f --- /dev/null +++ b/sdk/servicebus/azure-servicebus/samples/sync_samples/connection_to_custom_endpoint_address.py @@ -0,0 +1,40 @@ +#!/usr/bin/env python + +# -------------------------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +# -------------------------------------------------------------------------------------------- + +""" +Examples to show how to create async EventHubProducerClient and EventHubConsumerClient that connect to custom endpoint. +""" + +import os +from azure.servicebus import ServiceBusClient, ServiceBusMessage + + +CONNECTION_STR = os.environ['SERVICE_BUS_CONNECTION_STR'] +QUEUE_NAME = os.environ["SERVICE_BUS_QUEUE_NAME"] +# The custom endpoint address to use for establishing a connection to the Service Bus service, +# allowing network requests to be routed through any application gateways +# or other paths needed for the host environment. +CUSTOM_ENDPOINT_ADDRESS = 'sb://:' +# The optional absolute path to the custom certificate file used by client to authenticate the +# identity of the connection endpoint in the case that endpoint has its own issued CA. +# If not set, the certifi library will be used to load certificates. +CUSTOM_CA_BUNDLE_PATH = '' + +def send_single_message(sender): + message = ServiceBusMessage("Single Message") + sender.send_messages(message) + +servicebus_client = ServiceBusClient.from_connection_string( + conn_str=CONNECTION_STR, + logging_enable=True, + custom_endpoint_address=CUSTOM_ENDPOINT_ADDRESS, + connection_verify=CUSTOM_CA_BUNDLE_PATH + ) +with servicebus_client: + sender = servicebus_client.get_queue_sender(queue_name=QUEUE_NAME) + with sender: + send_single_message(sender) From 9f52911f48465c6938140ccc4dd67fc0ac81ec1e Mon Sep 17 00:00:00 2001 From: l0lawrence Date: Tue, 24 May 2022 16:25:27 -0700 Subject: [PATCH 07/10] trailing whitespace --- .../azure-servicebus/azure/servicebus/_common/_configuration.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/servicebus/azure-servicebus/azure/servicebus/_common/_configuration.py b/sdk/servicebus/azure-servicebus/azure/servicebus/_common/_configuration.py index 7129b1293a9d..d311cb0efbec 100644 --- a/sdk/servicebus/azure-servicebus/azure/servicebus/_common/_configuration.py +++ b/sdk/servicebus/azure-servicebus/azure/servicebus/_common/_configuration.py @@ -31,7 +31,7 @@ def __init__(self, **kwargs): self.auto_reconnect = kwargs.get("auto_reconnect", True) self.keep_alive = kwargs.get("keep_alive", 30) self.timeout = kwargs.get("timeout", 60) # type: float - + self.custom_endpoint_address = kwargs.get("custom_endpoint_address") # type: Optional[str] self.connection_verify = kwargs.get("connection_verify") # type: Optional[str] self.connection_port = DEFAULT_AMQPS_PORT From 2c5dd2de2e3cdc71c29a8d3d4bf0b77d4ca79ee0 Mon Sep 17 00:00:00 2001 From: l0lawrence Date: Wed, 25 May 2022 13:16:19 -0700 Subject: [PATCH 08/10] updating changelog --- sdk/servicebus/azure-servicebus/CHANGELOG.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/sdk/servicebus/azure-servicebus/CHANGELOG.md b/sdk/servicebus/azure-servicebus/CHANGELOG.md index e3b0fe19c3ac..8cec289da271 100644 --- a/sdk/servicebus/azure-servicebus/CHANGELOG.md +++ b/sdk/servicebus/azure-servicebus/CHANGELOG.md @@ -6,6 +6,15 @@ - Fixed bug to make AMQP exceptions retryable by default, if condition is not non-retryable, to ensure that InternalServerErrors are retried. +### Features Added + +- The `ServiceBusClient` constructor now accepts optional `custom_endpoint_address` argument +which allows for specifying a custom endpoint to use when communicating with the Event Hubs service, +and is useful when your network does not allow communicating to the standard Event Hubs endpoint. +- The `ServiceBusClient`constructor now accepts optional `connection_verify` argument +which allows for specifying the path to the custom CA_BUNDLE file of the SSL certificate which is used to authenticate +the identity of the connection endpoint. + ## 7.6.1 (2022-04-11) ### Other Changes From af9eda7e690fa0caa5701375ead65761bbbd5807 Mon Sep 17 00:00:00 2001 From: l0lawrence Date: Wed, 1 Jun 2022 14:29:50 -0700 Subject: [PATCH 09/10] pr comments --- sdk/servicebus/azure-servicebus/CHANGELOG.md | 4 ++-- .../azure/servicebus/_common/_configuration.py | 13 +++++++------ .../azure/servicebus/_servicebus_client.py | 4 ++-- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/sdk/servicebus/azure-servicebus/CHANGELOG.md b/sdk/servicebus/azure-servicebus/CHANGELOG.md index 8cec289da271..8d10e78de39c 100644 --- a/sdk/servicebus/azure-servicebus/CHANGELOG.md +++ b/sdk/servicebus/azure-servicebus/CHANGELOG.md @@ -9,8 +9,8 @@ ### Features Added - The `ServiceBusClient` constructor now accepts optional `custom_endpoint_address` argument -which allows for specifying a custom endpoint to use when communicating with the Event Hubs service, -and is useful when your network does not allow communicating to the standard Event Hubs endpoint. +which allows for specifying a custom endpoint to use when communicating with the Service Bus service, +and is useful when your network does not allow communicating to the standard Service Bus endpoint. - The `ServiceBusClient`constructor now accepts optional `connection_verify` argument which allows for specifying the path to the custom CA_BUNDLE file of the SSL certificate which is used to authenticate the identity of the connection endpoint. diff --git a/sdk/servicebus/azure-servicebus/azure/servicebus/_common/_configuration.py b/sdk/servicebus/azure-servicebus/azure/servicebus/_common/_configuration.py index d311cb0efbec..1effc8f2f48c 100644 --- a/sdk/servicebus/azure-servicebus/azure/servicebus/_common/_configuration.py +++ b/sdk/servicebus/azure-servicebus/azure/servicebus/_common/_configuration.py @@ -20,9 +20,15 @@ def __init__(self, **kwargs): self.retry_backoff_max = kwargs.get("retry_backoff_max", 120) # type: int self.logging_enable = kwargs.get("logging_enable", False) # type: bool self.http_proxy = kwargs.get("http_proxy") # type: Optional[Dict[str, Any]] + + self.custom_endpoint_address = kwargs.get("custom_endpoint_address") # type: Optional[str] + self.connection_verify = kwargs.get("connection_verify") # type: Optional[str] + self.connection_port = DEFAULT_AMQPS_PORT + self.custom_endpoint_hostname = None + self.transport_type = ( TransportType.AmqpOverWebsocket - if self.http_proxy + if self.http_proxy or self.custom_endpoint_address else kwargs.get("transport_type", TransportType.Amqp) ) # The following configs are not public, for internal usage only @@ -32,11 +38,6 @@ def __init__(self, **kwargs): self.keep_alive = kwargs.get("keep_alive", 30) self.timeout = kwargs.get("timeout", 60) # type: float - self.custom_endpoint_address = kwargs.get("custom_endpoint_address") # type: Optional[str] - self.connection_verify = kwargs.get("connection_verify") # type: Optional[str] - self.connection_port = DEFAULT_AMQPS_PORT - self.custom_endpoint_hostname = None - if self.http_proxy or self.transport_type == TransportType.AmqpOverWebsocket: self.transport_type = TransportType.AmqpOverWebsocket self.connection_port = DEFAULT_AMQP_WSS_PORT diff --git a/sdk/servicebus/azure-servicebus/azure/servicebus/_servicebus_client.py b/sdk/servicebus/azure-servicebus/azure/servicebus/_servicebus_client.py index 603ddb480a07..e51204bc5a38 100644 --- a/sdk/servicebus/azure-servicebus/azure/servicebus/_servicebus_client.py +++ b/sdk/servicebus/azure-servicebus/azure/servicebus/_servicebus_client.py @@ -77,7 +77,7 @@ class ServiceBusClient(object): # pylint: disable=client-accepts-api-version-key where default is "exponential". :paramtype retry_mode: str :keyword str custom_endpoint_address: The custom endpoint address to use for establishing a connection to - the Event Hubs service, allowing network requests to be routed through any application gateways or + the Service Bus service, allowing network requests to be routed through any application gateways or other paths needed for the host environment. Default is None. The format would be like "sb://:". If port is not specified in the `custom_endpoint_address`, by default port 443 will be used. @@ -208,7 +208,7 @@ def from_connection_string( where default is 'exponential'. :paramtype retry_mode: str :keyword str custom_endpoint_address: The custom endpoint address to use for establishing a connection to - the Event Hubs service, allowing network requests to be routed through any application gateways or + the Service Bus service, allowing network requests to be routed through any application gateways or other paths needed for the host environment. Default is None. The format would be like "sb://:". If port is not specified in the custom_endpoint_address, by default port 443 will be used. From 9ea1a4dab6efb7e482a56ee67420076256a11862 Mon Sep 17 00:00:00 2001 From: l0lawrence Date: Wed, 1 Jun 2022 14:47:42 -0700 Subject: [PATCH 10/10] removing fix for other pr --- .../azure-servicebus/azure/servicebus/_common/_configuration.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/servicebus/azure-servicebus/azure/servicebus/_common/_configuration.py b/sdk/servicebus/azure-servicebus/azure/servicebus/_common/_configuration.py index 1effc8f2f48c..a445e497b612 100644 --- a/sdk/servicebus/azure-servicebus/azure/servicebus/_common/_configuration.py +++ b/sdk/servicebus/azure-servicebus/azure/servicebus/_common/_configuration.py @@ -28,7 +28,7 @@ def __init__(self, **kwargs): self.transport_type = ( TransportType.AmqpOverWebsocket - if self.http_proxy or self.custom_endpoint_address + if self.http_proxy else kwargs.get("transport_type", TransportType.Amqp) ) # The following configs are not public, for internal usage only