Azure IOTHUB 错误连接关闭时无法创建会话

时间:2021-06-28 14:08:18

标签: azure azure-functions azure-iot-hub

我有 python azure 函数,它根据 Iothub 事件触发器从 azure IotHub 读取数据。 下面是我的代码

def main(events: List[func.EventHubEvent]):
    try:
        keyfunc = lambda x: (x.iothub_metadata['connection-device-id'])
        data = sorted(events, key=keyfunc)
        for k,v in itertools.groupby(data,keyfunc):
            dictionarylist = [dict(dic, deviceid=k) for dic in [json.loads(x.get_body().decode('utf-8')) for x in v]]
            insertdata(deviceid=k,datalist=dictionarylist)
            insertforprocessing(deviceid=k,datalist=dictionarylist)
    except Exception as e:
           print(e)

我不断收到以下错误并且没有处理数据。我不知道如何解决这个问题。

<块引用>

失败:Host.Triggers.EventHub[0] 来自分区 ID 的错误处理事件:'3',所有者:'d5cec505-7f60-4953-9e7a-89323b0fccd2',EventHubPath:'test-iothub-poulcs4smtna' System.InvalidOperationException:连接关闭时无法创建会话。 在 Microsoft.Azure.Amqp.AmqpConnection.AddSession(AmqpSession session, Nullable1 channel) at Microsoft.Azure.Amqp.AmqpCbsLink.OpenCbsRequestResponseLinkAsyncResult.GetAsyncSteps()+MoveNext() --- End of stack trace from previous location where exception was thrown --- at Microsoft.Azure.Amqp.AsyncResult.End[TAsyncResult](IAsyncResult result) at Microsoft.Azure.Amqp.AmqpCbsLink.EndCreateCbsLink(IAsyncResult result) at System.Threading.Tasks.TaskFactory1.FromAsyncCoreLogic(IAsyncResult iar, Func2 endFunction, Action1 endAction, Task1 promise, Boolean requiresSynchronization) --- End of stack trace from previous location where exception was thrown --- at Microsoft.Azure.Amqp.FaultTolerantAmqpObject1.OnCreateAsync(TimeSpan timeout) 在 Microsoft.Azure.Amqp.Singleton1.GetOrCreateAsync(TimeSpan timeout) at Microsoft.Azure.Amqp.Singleton1.GetOrCreateAsync(TimeSpan timeout) 在 Microsoft.Azure.Amqp.TaskHelpers.EndAsyncResult(IAsyncResult asyncResult) 在 Microsoft.Azure.Amqp.IteratorAsyncResult1.StepCallback(IAsyncResult result) --- End of stack trace from previous location where exception was thrown --- at Microsoft.Azure.Amqp.AsyncResult.End[TAsyncResult](IAsyncResult result) at Microsoft.Azure.Amqp.AmqpCbsLink.<>c__DisplayClass4_0.<SendTokenAsync>b__1(IAsyncResult a) at System.Threading.Tasks.TaskFactory1.FromAsyncCoreLogic(IAsyncResult iar, Func2 endFunction, Action1 endAction, Task1 promise, Boolean requiresSynchronization) --- End of stack trace from previous location where exception was thrown --- at Microsoft.Azure.EventHubs.Amqp.AmqpPartitionReceiver.CreateLinkAsync(TimeSpan timeout) at Microsoft.Azure.Amqp.FaultTolerantAmqpObject1.OnCreateAsync(TimeSpan timeout) 在 Microsoft.Azure.Amqp.Singleton1.GetOrCreateAsync(TimeSpan timeout) at Microsoft.Azure.Amqp.Singleton1.GetOrCreateAsync(TimeSpan timeout) 在 Microsoft.Azure.EventHubs.Amqp.AmqpPartitionReceiver.OnReceiveAsync(Int32 maxMessageCount, TimeSpan waitTime) 在 Microsoft.Azure.EventHubs.Amqp.AmqpPartitionReceiver.OnReceiveAsync(Int32 maxMessageCount, TimeSpan waitTime) 在 Microsoft.Azure.EventHubs.PartitionReceiver.ReceiveAsync(Int32 maxMessageCount, TimeSpan waitTime) 在 Microsoft.Azure.EventHubs.Amqp.AmqpPartitionReceiver.ReceivePumpAsync(CancellationToken cancellingToken, Boolean invokeWhenNoEvents)

0 个答案:

没有答案