簡體   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