-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Description
- Package Name: azure-servicebus
- Package Version: 7.14.2
- Operating System: Linux
- Python Version: 3.10
Describe the bug
Tried to establish a connection to ASB Topic - Subscriber via databricks notebook. I have created a secret scope in databricks.
Tried to get the secret - NAMESPACE_CONNECTION_STR = dbutils.secrets.get(scope = "Scope-QA", key = "int-QA").
But I am encountering an error.
Validated that Port 5671 is reachable & Port 443 is reachable.
Respective Roles were also assigned to the namespace:
Azure Service Bus Data Receiver
Azure Service Bus Data Owner
Installed the packages -
Run this in its own cell
%pip install --upgrade
azure-servicebus==7.12.1
azure-identity==1.17.1
aiohttp==3.9.5
aiosignal==1.3.1
frozenlist==1.4.1
yarl==1.9.4
multidict==6.0.5
To Reproduce
Steps to reproduce the behavior:
- Once we are able to establish the connection, then I can run it in continuous loop to keep consuming the data objects.
CODE:
dbutils.library.restartPython()
import json
import asyncio
from azure.servicebus.aio import ServiceBusClient
from azure.identity.aio import DefaultAzureCredential
Async client
from azure.servicebus.aio import ServiceBusClient
NAMESPACE_CONNECTION_STR = dbutils.secrets.get("Scope-QA", "int-QA")
TOPIC_NAME = "topic.uat"
SUBSCRIPTION_NAME = "asub-uat"
async def run_once(max_count=20, wait_sec=5):
async with ServiceBusClient.from_connection_string(
conn_str=NAMESPACE_CONNECTION_STR,
logging_enable=True,
) as sb_client:
receiver = sb_client.get_subscription_receiver(
topic_name=TOPIC_NAME,
subscription_name=SUBSCRIPTION_NAME,
prefetch_count=200,
)
async with receiver:
msgs = await receiver.receive_messages(
max_message_count=max_count,
max_wait_time=wait_sec
)
print(f"Received {len(msgs)} message(s)")
for m in msgs:
body = b"".join(m.body)
preview = body[:200].decode("utf-8", errors="ignore")
print(f"id={m.message_id} seq={m.sequence_number} preview={preview!r}")
await receiver.complete_message(m)
await run_once()
Error I am getting :
Requirement already satisfied: cffi>=1.12 in /databricks/python3/lib/python3.10/site-packages (from cryptography>=2.5->azure-identity==1.17.1) (1.15.1)
Requirement already satisfied: PyJWT[crypto]<3,>=1.0.0 in /usr/lib/python3/dist-packages (from msal>=1.24.0->azure-identity==1.17.1) (2.3.0)
Requirement already satisfied: pycparser in /databricks/python3/lib/python3.10/site-packages (from cffi>=1.12->cryptography>=2.5->azure-identity==1.17.1) (2.21)
Requirement already satisfied: charset-normalizer<3,>=2 in /databricks/python3/lib/python3.10/site-packages (from requests>=2.21.0->azure-core>=1.28.0->azure-servicebus==7.12.1) (2.0.4)
Requirement already satisfied: urllib3<1.27,>=1.21.1 in /databricks/python3/lib/python3.10/site-packages (from requests>=2.21.0->azure-core>=1.28.0->azure-servicebus==7.12.1) (1.26.14)
Requirement already satisfied: certifi>=2017.4.17 in /databricks/python3/lib/python3.10/site-packages (from requests>=2.21.0->azure-core>=1.28.0->azure-servicebus==7.12.1) (2022.12.7)
Installing collected packages: typing-extensions, multidict, isodate, frozenlist, async-timeout, yarl, azure-core, aiosignal, azure-servicebus, aiohttp, msal, msal-extensions, azure-identity
Attempting uninstall: typing-extensions
Found existing installation: typing_extensions 4.4.0
Not uninstalling typing-extensions at /databricks/python3/lib/python3.10/site-packages, outside environment /local_disk0/.ephemeral_nfs/envs/pythonEnv-c02c48e2-fb34-459b-a95c-3b11923c0a19
Can't uninstall 'typing_extensions'. No files were found to uninstall.
Successfully installed aiohttp-3.9.5 aiosignal-1.3.1 async-timeout-4.0.3 azure-core-1.36.0 azure-identity-1.17.1 azure-servicebus-7.12.1 frozenlist-1.4.1 isodate-0.7.2 msal-1.34.0 msal-extensions-1.3.1 multidict-6.0.5 typing-extensions-4.15.0 yarl-1.9.4
ServiceBusAuthenticationError: Service Bus has encountered an error. Error condition: amqp:client-error.
Expected behavior
A clear and concise description of what you expected to happen.
Screenshots
If applicable, add screenshots to help explain your problem.
Additional context
Add any other context about the problem here.