[英]Azure Service Bus Error: Ensure RequiresSession is set to true when creating a Queue, with Databricks
When attempting to retrieve Queue messages from Azure Service via Databricks I get the following error:尝试通过 Databricks 从 Azure 服务检索队列消息时,出现以下错误:
Ensure RequiresSession is set to true when creating a Queue or Subscription to enable sessionful behavior确保在创建队列或订阅时将 RequiresSession 设置为 true 以启用会话行为
I have set the Message Queue using Azure's Service Bus Explorer, see below我已经使用 Azure 的服务总线资源管理器设置了消息队列,见下文
As you can see I have set the sessionId to carlsession6如您所见,我已将 sessionId 设置为 carlsession6
Therefore, I'm not sure why I'm getting the error message因此,我不确定为什么会收到错误消息
The code in databricks is as follows: 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))
Any thoughts on how to resolve the error?关于如何解决错误的任何想法?
Problem resolved with the following code:使用以下代码解决了问题:
New-AzServiceBusQueue -ResourceGroup myresourcegroup -NamespaceName mynamespace
-QueueName myqueue ` -RequiresSession $True New-AzServiceBusQueue -ResourceGroup
-NamespaceName mynamespace
-RequiresSession $True
As described at the following link https://learn.microsoft.com/en-us/azure/service-bus-messaging/enable-message-sessions如以下链接所述 https://learn.microsoft.com/en-us/azure/service-bus-messaging/enable-message-sessions
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.