繁体   English   中英

Azure 服务总线错误:使用 Databricks 创建队列时确保 RequiresSession 设置为 true

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM