【问题标题】:Function Running in local and not when deployed to Azure功能在本地运行,而不是在部署到 Azure 时运行
【发布时间】:2021-02-27 07:29:19
【问题描述】:

我有一个http触发功能,当我向url发送消息时,它会根据需要将数据记录在queuestorage上;

http://localhost:7071/api/xxxx?message=89000

但是,当我在 azure 中对函数 url 执行相同操作时

https://yyyyy.azurewebsites.net/api/xxxx?message=89000 没有任何记录。

我该如何解决这个问题?

另一个问题; 底层代码是

import logging
import azure.functions as func
def main(req: func.HttpRequest,msg: func.Out[str]) -> func.HttpResponse:
    logging.info('Python HTTP trigger function processed a request.')
    input_msg = req.params.get('message')
    logging.info(input_msg)
    msg.set(input_msg)
    return func.HttpResponse(
            "This is a test.",
            status_code=200
    )

预计会收到如下payload

{
    "layerId":0,
    "serviceName": "myService",
    "changeType": "FeaturesCreated",
    "orgId": "myorgId"
    "changesUrl": "https://olserver/services/myService/FeatureService/extractChanges?serverGens=[1122, 1124]"
}

当我执行http://localhost:7071/api/xxxx?message=89000 时,它会很好地记录队列存储,但不会在传递此有效负载时记录。我该如何配置?

【问题讨论】:

  • 还有什么问题吗?如果没有,也许我们可以结束这个问题?

标签: azure-function-app azure-http-trigger


【解决方案1】:

Azure 函数应用不会从门户上的 local.settings.json 获取环境变量。

您需要添加以下设置:

并且为了防止由于队列的某些设置而无法保存消息,您可以尝试创建一个新队列来避免这种情况。

【讨论】:

  • 在这一项上,如果我希望应用程序记录 message={ "layerId":0, "serviceName": "myService", "changeType": "FeaturesUpdated", "orgId": "myorgId" "changesUrl": "https://olserver/services/myService/FeatureService/extractChanges?serverGens=[1122, 1124]" } 而不是 message=20000 是否有设置调整?
  • @wwnde 队列绑定的底层代码我没看过,但是很可能是基于字符串的。或许可以像普通字符串一样写入队列,然后在读取时使用一些模块进行转换。
  • @wwnde 可以正常书写没有问题,但是应该没有嵌套结构
  • 查看我的编辑。是否可以配置代码以期望有效负载?
  • @wwnde 我暂时在外面有事。我周围没有电脑。我回去帮你做个测试。
猜你喜欢
  • 1970-01-01
  • 2022-07-05
  • 1970-01-01
  • 2014-03-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-11-02
  • 1970-01-01
相关资源
最近更新 更多