【问题标题】:Azure Function App & Event Hub Messages - Function Stopped WorkingAzure 函数应用和事件中心消息 - 函数停止工作
【发布时间】:2020-06-10 09:58:16
【问题描述】:

我创建了一个带有事件中心触发器的函数。 直到今天它一直按预期工作。

import logging
import datetime
import json
import azure.functions as func


def main(event: func.EventHubEvent, msg: func.Out[func.QueueMessage]):
    try:
        # take the number from the event
        number = json.loads(event.get_body().decode('utf-8'))[0]["number"]

        # send number to queue
        msg.set(number)

        logging.info('Receive function processed ' + number + '.')

    except Exception as err:
        logging.error('Event hub message did not contain number. Error: ' + str(err))

函数报错

事件中心消息不包含数字。错误:“列表”对象没有属性“get_body”

我可以在 Application Insights 的日志中看到包含以下消息的跟踪:

从分区 ID:“0”引发了“ReceiverDisconnectedException”类型的事件中心异常。这种异常类型通常是事件中心处理器重新平衡的结果,可以安全地忽略

当我使用 VS 代码在本地运行该函数时,它能够从事件中心读取消息。

知道为什么它停止工作了吗?

【问题讨论】:

    标签: python azure azure-eventhub azure-function-app


    【解决方案1】:

    我通过更改这行代码来修复它,当使用 VS 代码在本地运行时仍然有效

    json.loads(event.get_body().decode('utf-8'))[0]["number"]
    

    到这里

    json.loads(event[0].get_body().decode('utf-8'))["number"]
    

    当我在 Azure 中运行该函数时,这现在可以工作了。不知道为什么格式发生了变化。

    我已经在 requirements.txt 文件中指定了模块的版本。

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-10-06
    • 1970-01-01
    • 1970-01-01
    • 2023-03-05
    • 2017-10-07
    • 1970-01-01
    • 2021-05-22
    • 1970-01-01
    相关资源
    最近更新 更多