Daniil Grankin
Daniil Grankin

Reputation: 3933

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.

Upvotes: 1

Views: 794

Answers (1)

suziki
suziki

Reputation: 14098

Use your host.json also get the same problem:

enter image description here

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:

enter image description here

enter image description here

Upvotes: 1

Related Questions