简体   繁体   中英

ServiceBus binding breaks Node.js Azure Function

I have simple azure function which is triggered by 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"
    }
  ]
}

At this point I can trigger the function and see the response.

Then I try to add a service bus binding to 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. 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.

host.json (just in case)

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

Runtime version ~2

Node.js Version Node.js 12 LTS

App is run in read only mode from a package file.

AppType functionAppLinux

UPDATE I created the function with VS Code Azure Function Extension and deployed with DevOps. Later I created function in azure portal manually. Compared with App Service Editor files of both functions and found out that my first function doesn't have extensionBundle in host.json. That was the reason.

Use your host.json also get the same problem:

在此处输入图像描述

The problem seems comes from the host.json in your function app.

On my side those files is:

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

host.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="
  }
}

And it worked:

在此处输入图像描述

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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