-2

I have a nodejs application. there are 3 functions and 2 HTTP calls.

here is my function.json for the HTTP route:

{
  "bindings": [
    {
      "authLevel": "function",
      "type": "httpTrigger",
      "direction": "in",
      "name": "req",
      "methods": ["post"]
    },
    {
      "type": "http",
      "direction": "out",
      "name": "res"
    },
    {
      "name": "firstStep",
      "type": "serviceBus",
      "queueName": "firststepqueue",
      "connection": "MyServiceBus",
      "direction": "out"
    }
  ],
  "scriptFile": "../dist/firstStep/index.js"
}

and here when I want to bind:

context.bindings.firstStep = message;
context.res = {
    status: 200,
    body: {"message": "success"},
    headers: {
        'Content-Type': 'application/json'
    }
};
context.done();

But the queues are not working in Azure.

it works in my local when I run func start.

there is no error!

1 Answers1

0

There is no need to specify the script file.

Below works both on local and azure on my side:

index.js

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

    var message = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
    context.log(message);   
    context.bindings.firstStep = message;
    context.res = {
        // status: 200, /* Defaults to 200 */
        body: "test"
    };
}

function.json

{
  "bindings": [
    {
      "authLevel": "anonymous",
      "type": "httpTrigger",
      "direction": "in",
      "name": "req",
      "methods": [
        "get",
        "post"
      ]
    },
    {
      "type": "http",
      "direction": "out",
      "name": "res"
    },
    {
      "name": "firstStep",
      "type": "serviceBus",
      "queueName": "firststepqueue",
      "connection": "MyServiceBus",
      "direction": "out"
    }
  ]
}

local.settings.json

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

host.json

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

Configuration Settings on Azure

enter image description here

Cindy Pau
  • 13,085
  • 1
  • 15
  • 27
  • Thanks for your response, I need to define "scriptFile". because I'm using typescript. when I don't have scriptFile, I get Microsoft.Azure.WebJobs.Script: Did not find functions with language [node]. Value cannot be null. (Parameter 'provider'). – Masoud Jahromi Feb 19 '21 at 16:44