From 33824da5bd832c7d3099d1cb0b46b4da53e67fb7 Mon Sep 17 00:00:00 2001 From: Swathi Pillalamarri Date: Thu, 17 Jun 2021 15:37:43 -0700 Subject: [PATCH 1/3] extract iot hub name from redirect address --- .../async_samples/iot_hub_connection_string_receive_async.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/sdk/eventhub/azure-eventhub/samples/async_samples/iot_hub_connection_string_receive_async.py b/sdk/eventhub/azure-eventhub/samples/async_samples/iot_hub_connection_string_receive_async.py index 9a42e6cb7f07..ee8b0f8ca3dc 100644 --- a/sdk/eventhub/azure-eventhub/samples/async_samples/iot_hub_connection_string_receive_async.py +++ b/sdk/eventhub/azure-eventhub/samples/async_samples/iot_hub_connection_string_receive_async.py @@ -15,6 +15,7 @@ """ import os +import re import time from base64 import b64encode, b64decode from hashlib import sha256 @@ -80,6 +81,8 @@ def convert_iothub_to_eventhub_conn_str(iothub_conn_str): # Once a redirect error is received, close the original client and recreate a new one to the re-directed address receive_client.close() fully_qualified_name = redirect.hostname.decode("utf-8") + # Use regular expression to parse the Event Hub name from the IoT Hub redirection address + iot_hub_name = re.search(":\d+\/.*/ConsumerGroups", str(redirect.address)).group(0).split("/")[1] return "Endpoint=sb://{}/;SharedAccessKeyName={};SharedAccessKey={};EntityPath={}".format( fully_qualified_name, shared_access_key_name, From ba91b5bdd39947afe34cb6e94789e83c779607da Mon Sep 17 00:00:00 2001 From: Swathi Pillalamarri Date: Thu, 17 Jun 2021 15:40:21 -0700 Subject: [PATCH 2/3] update --- .../async_samples/iot_hub_connection_string_receive_async.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sdk/eventhub/azure-eventhub/samples/async_samples/iot_hub_connection_string_receive_async.py b/sdk/eventhub/azure-eventhub/samples/async_samples/iot_hub_connection_string_receive_async.py index ee8b0f8ca3dc..8b03490a0b44 100644 --- a/sdk/eventhub/azure-eventhub/samples/async_samples/iot_hub_connection_string_receive_async.py +++ b/sdk/eventhub/azure-eventhub/samples/async_samples/iot_hub_connection_string_receive_async.py @@ -82,7 +82,8 @@ def convert_iothub_to_eventhub_conn_str(iothub_conn_str): receive_client.close() fully_qualified_name = redirect.hostname.decode("utf-8") # Use regular expression to parse the Event Hub name from the IoT Hub redirection address - iot_hub_name = re.search(":\d+\/.*/ConsumerGroups", str(redirect.address)).group(0).split("/")[1] + if redirect.address: + iot_hub_name = re.search(":\d+\/.*/ConsumerGroups", str(redirect.address)).group(0).split("/")[1] return "Endpoint=sb://{}/;SharedAccessKeyName={};SharedAccessKey={};EntityPath={}".format( fully_qualified_name, shared_access_key_name, From 650d5df3ac21a03d9690f00a28a5dc5ca47e50ec Mon Sep 17 00:00:00 2001 From: Swathi Pillalamarri Date: Wed, 23 Jun 2021 16:22:45 -0700 Subject: [PATCH 3/3] add comment --- .../async_samples/iot_hub_connection_string_receive_async.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/sdk/eventhub/azure-eventhub/samples/async_samples/iot_hub_connection_string_receive_async.py b/sdk/eventhub/azure-eventhub/samples/async_samples/iot_hub_connection_string_receive_async.py index 8b03490a0b44..494b817a9b3f 100644 --- a/sdk/eventhub/azure-eventhub/samples/async_samples/iot_hub_connection_string_receive_async.py +++ b/sdk/eventhub/azure-eventhub/samples/async_samples/iot_hub_connection_string_receive_async.py @@ -83,6 +83,10 @@ def convert_iothub_to_eventhub_conn_str(iothub_conn_str): fully_qualified_name = redirect.hostname.decode("utf-8") # Use regular expression to parse the Event Hub name from the IoT Hub redirection address if redirect.address: + # The regex searches for the Event Hub compatible name in the redirection address. The name is nested in + # between the port and 'ConsumerGroups'. + # (ex. "...servicebus.windows.net:12345//ConsumerGroups/..."). + # The regex matches string ':/', then any characters, then the string '/ConsumerGroups'. iot_hub_name = re.search(":\d+\/.*/ConsumerGroups", str(redirect.address)).group(0).split("/")[1] return "Endpoint=sb://{}/;SharedAccessKeyName={};SharedAccessKey={};EntityPath={}".format( fully_qualified_name,