繁体   English   中英

ServiceBus 绑定中断 Node.js Azure Function

[英]ServiceBus binding breaks Node.js Azure Function

我有简单的 azure function 由 http 触发

module.exports = async function (context, req) {
    context.log('JavaScript HTTP trigger function processed a request.');

    context.res = {
        // status: 200, /* Defaults to 200 */
        body: "Success"
    };
}

function.json

{
  "bindings": [
    {
      "authLevel": "function",
      "type": "httpTrigger",
      "direction": "in",
      "name": "req",
      "methods": [
        "get",
        "post"
      ]
    },
    {
      "type": "http",
      "direction": "out",
      "name": "res"
    }
  ]
}

此时我可以触发 function 并查看响应。

然后我尝试添加一个服务总线绑定到 function.json

{
  "bindings": [
    ...
    {
      "type": "serviceBus",
      "direction": "out",
      "name": "outputSbTopic",
      "topicName": "topicName",
      "connection": "ServiceBusConnection"
    }
  ]
}

当我添加绑定时,function 返回 404,并且日志中没有任何内容。 我什至还没有开始使用绑定。

有什么问题? 我在这个问题上苦苦挣扎了 2 个多小时,没有更多的想法。

host.json(以防万一)

{
  "version": "2.0",
  "extensions": {
    "serviceBus": {
      "prefetchCount": 100,
      "messageHandlerOptions": {
        "autoComplete": true,
        "maxConcurrentCalls": 32,
        "maxAutoRenewDuration": "00:05:00"
      }
    }
  }
}

运行时版本~2

Node.js 版本 Node.js 12 LTS

应用程序从 package 文件以只读模式运行。

AppType函数AppLinux

更新我使用 VS Code Azure Function 扩展创建了 function 并使用 DevOps 进行了部署。 后来我在azure入口手动创建了function。 对比两个函数的App Service Editor文件,发现我的第一个function在host.json中没有extensionBundle 这就是原因。

使用你的 host.json 也遇到同样的问题:

在此处输入图像描述

问题似乎来自您的 function 应用程序中的 host.json。

在我这边,这些文件是:

索引.js

module.exports = async function (context, req) {
    context.log('JavaScript HTTP trigger function processed a request.');
    var message = "This is a test to output to service bus.";
    context.bindings.testbowman = message;
    context.done();
    context.res = {
        status: 200,
        body: "This is a test to output to service bus topic."
    };
};

function.json

{
  "bindings": [
    {
      "authLevel": "anonymous",
      "type": "httpTrigger",
      "direction": "in",
      "name": "req",
      "methods": [
        "get",
        "post"
      ]
    },
    {
      "type": "http",
      "direction": "out",
      "name": "res"
    },
    {
        "name": "testbowman",
        "type": "serviceBus",
        "topicName": "testbowman",
        "connection": "str",
        "direction": "out"
    }
  ]
}

主机.json

{
  "version": "2.0",
  "logging": {
    "applicationInsights": {
      "samplingSettings": {
        "isEnabled": true,
        "excludedTypes": "Request"
      }
    }
  },
  "extensionBundle": {
    "id": "Microsoft.Azure.Functions.ExtensionBundle",
    "version": "[1.*, 2.0.0)"
  }
}

local.settings.json

{
  "IsEncrypted": false,
  "Values": {
    "AzureWebJobsStorage": "",
    "FUNCTIONS_WORKER_RUNTIME": "node",
    "str":"Endpoint=sb://testbowman.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=xxxxxx="
  }
}

它起作用了:

在此处输入图像描述

在此处输入图像描述

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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