Strip port from strip_protocol_from_uri
Is your feature request related to a problem? Please describe. I noticed a discrepancy in .net asb sdk and python sdk when it comes to parsing the fully_qualified_namespace. Half of my team is developing in .net and we get the namespace url in the following format:
https://<myservicebus>.servicebus.windows.net:443/
i.e. it ends with the port :443/. Connecting to it like:
from azure.identity.aio import DefaultAzureCredential
from azure.servicebus.aio import ServiceBusClient
client = ServiceBusClient(
fully_qualified_namespace="myservicebus.servicebus.windows.net:443/",
credential=DefaultAzureCredential(),
)
rec=client.get_queue_receiver("myqueue")
msgs=await rec.receive_messages(max_wait_time=1)
Results in an error:
azure.servicebus.exceptions.ServiceBusAuthenticationError: Service Bus has encountered an error. Error condition: amqp:client-error.
Whereas connecting without port, i.e.:
client = ServiceBusClient(
fully_qualified_namespace="myservicebus.servicebus.windows.net",
credential=DefaultAzureCredential(),
)
rec=client.get_queue_receiver("myqueue")
msgs=await rec.receive_messages(max_wait_time=1)
Worked as expected. It was not immediately clear to me why, especially because it worked for my .net colleagues.
Describe the solution you'd like
In azure.servicebus._common.utils I'd prefer to see something like:
def parse_namespace_from_uri(uri: str) -> str:
"""Removes the protocol (e.g. http:// or sb://) and port (e.g. :443/) from a URI, such as the FQDN.
:param str uri: The URI to modify.
:return: The URI without the protocol.
:rtype: str
"""
left_slash_pos = uri.find("//")
if left_slash_pos != -1:
uri = uri[left_slash_pos + 2 :]
colon_pos = uri.find(":")
if colon_pos != -1:
uri = uri[colon_pos:]
return uri
Describe alternatives you've considered Removing port manually works fine. Additional context Add any other context or screenshots about the feature request here.
Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @EldertGrootenboer @skarri-microsoft.
The TypeScript SDK also does the stripping by itself AFAIK
and we get the namespace url in the following format:
https://<myservicebus>.servicebus.windows.net:443/
Note that this is the format that Azure returns when you create a new ServiceBus namespace:
Since the deployment doesn't return the URL in an acceptable format, someone needs to do this stripping. It would be best if the Azure SDK library did it, and not all of its users.
cc @johanste