![](/img/trans.png)
[英]Not able to set maxMessageBatchSize for Azure Service Bus Queue
[英]Azure Service Bus Error: Ensure RequiresSession is set to true when creating a Queue, with Databricks
嘗試通過 Databricks 從 Azure 服務檢索隊列消息時,出現以下錯誤:
確保在創建隊列或訂閱時將 RequiresSession 設置為 true 以啟用會話行為
我已經使用 Azure 的服務總線資源管理器設置了消息隊列,見下文
如您所見,我已將 sessionId 設置為 carlsession6
因此,我不確定為什么會收到錯誤消息
databricks中的代碼如下:
session_id = "carlsession6"
connstr = "Endpoint=sb://carlsbus.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=myaccesskey"
queue_name = "carlsqueue"
prevTable = None
table = None
rows = []
msgs = []
run = True
batchMsgs = 0
totalMsgs = 0
with ServiceBusClient.from_connection_string(connstr) as client:
# max_wait_time specifies how long the receiver should wait with no incoming messages before stopping receipt.
# Default is None; to receive forever.
while run:
with client.get_queue_receiver(queue_name, session_id=session_id, max_wait_time=5) as receiver:
logDebug(D_LEVEL[1], 'GOT QUEUE RECEIVER')
rows = []
msgs = []
i = 0
for msg in receiver:
receiver.session.renew_lock()
logDebug(D_LEVEL[1], 'READ MESSAGE')
msgs.append(msg)
msgJSON = json.loads(str(msg))
if 'table' in msgJSON['control']:
table = msgJSON['control']['table']
if prevTable is None:
prevTable = table
if prevTable != table or batchMsgs >= MAX_BATCH_SIZE:
writeData(prevTable, schema, rows, msgs)
rows = []
msgs = []
batchMsgs = 0
prevTable = table
i += 1
batchMsgs += 1
if (i % 100 == 0):
logInfo('Processed ' + str(i) + ' messages')
if 'operation' in msgJSON['control']:
if msgJSON['control']['operation'] == "stop_message_processor":
logInfo('RECEIVED stop_message_processor...')
run = False
break
schema, rows = processMsg(msgJSON, rows)
logDebug(D_LEVEL[1], 'COMPLETED MESSAGE')
if STOP_AFTER is not None:
if i >= STOP_AFTER:
run = False
break
if len(rows) > 0:
writeData(table, schema, rows, msgs)
elif len(msgs) == 1:
receiver.complete_message(msg)
logInfo('PROCESSED ' + str(i) + ' MESSAGES FROM QUEUE')
totalMsgs += i
logInfo('TOTAL MESSAGES PROCESSED ' + str(totalMsgs))
關於如何解決錯誤的任何想法?
使用以下代碼解決了問題:
New-AzServiceBusQueue -ResourceGroup -NamespaceName mynamespace
-RequiresSession $True
如以下鏈接所述 https://learn.microsoft.com/en-us/azure/service-bus-messaging/enable-message-sessions
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.