简体   繁体   English

ServiceBus 绑定中断 Node.js Azure Function

[英]ServiceBus binding breaks Node.js Azure Function

I have simple azure function which is triggered by http我有简单的 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 function.json

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

At this point I can trigger the function and see the response.此时我可以触发 function 并查看响应。

Then I try to add a service bus binding to function.json然后我尝试添加一个服务总线绑定到 function.json

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

When I add the binding the function returns 404 and there is nothing in log.当我添加绑定时,function 返回 404,并且日志中没有任何内容。 I've even not started to use the binding.我什至还没有开始使用绑定。

What can be wrong?有什么问题? I'm struggling with the issue more than 2 hours and have no more ideas.我在这个问题上苦苦挣扎了 2 个多小时,没有更多的想法。

host.json (just in case) host.json(以防万一)

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

Runtime version ~2运行时版本~2

Node.js Version Node.js 12 LTS Node.js 版本 Node.js 12 LTS

App is run in read only mode from a package file.应用程序从 package 文件以只读模式运行。

AppType functionAppLinux AppType函数AppLinux

UPDATE I created the function with VS Code Azure Function Extension and deployed with DevOps.更新我使用 VS Code Azure Function 扩展创建了 function 并使用 DevOps 进行了部署。 Later I created function in azure portal manually.后来我在azure入口手动创建了function。 Compared with App Service Editor files of both functions and found out that my first function doesn't have extensionBundle in host.json.对比两个函数的App Service Editor文件,发现我的第一个function在host.json中没有extensionBundle That was the reason.这就是原因。

Use your host.json also get the same problem:使用你的 host.json 也遇到同样的问题:

在此处输入图像描述

The problem seems comes from the host.json in your function app.问题似乎来自您的 function 应用程序中的 host.json。

On my side those files is:在我这边,这些文件是:

index.js索引.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 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"
    }
  ]
}

host.json主机.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 local.settings.json

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

And it worked:它起作用了:

在此处输入图像描述

在此处输入图像描述

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

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