亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

azure.servicebus.common.errors.ServiceBus

azure.servicebus.common.errors.ServiceBus

米琪卡哇伊 2023-07-27 09:46:22
我正在使用適用于 Python 的 Azure 服務總線庫從隊列中讀取消息。x 時間段后我收到以下錯誤:Traceback (most recent call last):  File "/opt/anaconda3/lib/python3.7/site-packages/uamqp/authentication/cbs_auth.py", line 76, in create_authenticator    self._connection.container_id)  File "./src/cbs.pyx", line 73, in uamqp.c_uamqp.CBSTokenAuth.__cinit__ValueError: Unable to open CBS link.During handling of the above exception, another exception occurred:Traceback (most recent call last):  File "/opt/anaconda3/lib/python3.7/site-packages/azure/servicebus/receive_handler.py", line 309, in open    self._handler.open(connection=self.connection)  File "/opt/anaconda3/lib/python3.7/site-packages/uamqp/client.py", line 259, in open    self._build_session()  File "/opt/anaconda3/lib/python3.7/site-packages/uamqp/client.py", line 214, in _build_session    on_attach=self._on_attach)  File "/opt/anaconda3/lib/python3.7/site-packages/uamqp/authentication/cbs_auth.py", line 82, in create_authenticator    "Please confirm target hostname exists: {}".format(connection.container_id, connection.hostname))uamqp.errors.AMQPConnectionError: Unable to open authentication session on connection b'SBReceiver-00000000-0000-0000-0000-000000000000'.Please confirm target hostname exists: b'myhostname.servicebus.windows.net'During handling of the above exception, another exception occurred:Traceback (most recent call last):  File "/opt/anaconda3/lib/python3.7/runpy.py", line 193, in _run_module_as_main    "__main__", mod_spec)  File "/opt/anaconda3/lib/python3.7/runpy.py", line 85, in _run_code    exec(code, run_globals)  File "/path/to/main.py", line 648, in <module>    main()  File "/path/to/main.py", line 631, in main    run_service_bus()  File "/path/to/main.py", line 482, in run_service_bus    with my_client.get_receiver() as queue_receiver:我認為這里發生的事情是在一段時間后我擁有的令牌過期了。處理這個問題的正確方法是什么?
查看完整描述

1 回答

?
臨摹微笑

TA貢獻1982條經驗 獲得超2個贊

正如評論中所討論的,這種情況下的問題很可能是由于網絡瞬態錯誤造成的,這在分布式環境中很正常。大多數情況下,暫時性錯誤可以通過重試來恢復。不幸的是,在v0.50.x的舊版 python 服務總線 SDK 中,沒有開箱即用的重試功能。最新的 V7 SDK中添加了指數回退重試(目前處于預覽版,很快將成為 GA)。具體可以參考v0.50到v7的遷移指南。下面是使用 V7 SDK 的接收器代碼示例(注意:同步變體,還有異步支持,您可以在廣泛的示例列表中查看。

V7 SDK 現在允許您為客戶端傳遞重試參數。雖然默認值一般來說應該足夠了。

retry_total:允許的重試總數。優先于其他計數。默認值為 10。

retry_backoff_factor:在第二次嘗試之后在嘗試之間應用的退避因子(大多數錯誤可以通過第二次嘗試立即解決,沒有延遲)。在固定模式下,重試策略將始終休眠 {backoff Factor}。在“指數”模式下,重試策略將休眠:{退避因子} * (2 ** ({總重試次數} - 1)) 秒。如果 backoff_factor 為 0.1,則重試將在重試之間休眠 [0.0s, 0.2s, 0.4s, ...]。默認值為 0.8。

retry_backoff_max:最大回退時間。默認值為 120(以秒為單位)。

servicebus_client = ServiceBusClient.from_connection_string(conn_str=CONNECTION_STR, retry_total=10, retry_backoff_factor=1, retry_backoff_max=30)


with servicebus_client:

? ? receiver = servicebus_client.get_queue_receiver(queue_name=QUEUE_NAME)

? ? with receiver:

? ? ? ? received_msgs = receiver.receive_messages(max_message_count=10, max_wait_time=5)

? ? ? ? for msg in received_msgs:

? ? ? ? ? ? print(str(msg))

? ? ? ? ? ? msg.complete()


查看完整回答
反對 回復 2023-07-27
  • 1 回答
  • 0 關注
  • 124 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號