3
votes

I'm trying to create a Function that is triggered when a message becomes available in an Azure Service Bus subscription. I followed the brief example from the official docs.

Running the app locally via func host start leads to the following error: "ServiceBusTriggerJS: The binding type 'serviceBusTrigger' is not registered. Please ensure the type is correct and the binding extension is installed."

My setup:

package.json contains the azure node module: "azure": "^2.2.1-preview". Node version is 8.11.

function.json is as in the example:

{
  "disabled": false,
  "bindings": [
    {
      "topicName": "myTopic",
      "subscriptionName": "mySubscription",
      "connection": "MyServiceBus",
      "name": "myQueueItem",
      "type": "serviceBusTrigger",
      "direction": "in"
    }
  ]
}

local.settings.json contains connection strings to the Service Bus and a storage account that is necessary for running locally:

{
  "IsEncrypted": false,
  "Values": {
    "AzureWebJobsStorage": "DefaultEndpointsProtocol=https;AccountName=...",
    "MyServiceBus": "Endpoint=sb://...servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=..."
  }
}

index.js is the same as the example, too:

module.exports = function (context, myQueueItem) {
    context.log('JavaScript queue trigger function processed work item', myQueueItem);
    context.done();
};

EDIT: This is similar to this question: The binding type 'serviceBusTrigger' is not registered error in azure functions c# with core tools 2. The problem (and therefore solution) are the same. I find the answer here straight-forward to implement.

2
@JerryLiu: It's similar, but not a duplicate, because the framework here is Node/JS, whereas in your linked question it is NET/C#.Thomas Schreiter
Sorry for lack of explanation. Language doesn't matter. I will write a complete answer for your to refer.Jerry Liu
Oh, I misinterpreted your comment indeed. And now I reread the official documentation. Indeed, I had not installed the bindings. But it still doesn't work. More details in a comment to your answer.Thomas Schreiter
What version of the Functions core tools did you install? What host version do you see when you run func host start?brettsam
@brettsam: I did some installing and uninstalling. Now when everything is working I have: tools version = 220.0.0-beta.0, runtime version = 2.0.11651,Thomas Schreiter

2 Answers

3
votes

You should install the servicebus extension using

func extensions install --package Microsoft.Azure.WebJobs.ServiceBus --version 3.0.0-beta5.

The extension is used to register the servicebus trigger, making the trigger recognized by your local function run time. It is like a complement for the run time, so it doesn't matter what language you use.

Everything works on my side(js function), feel free to ask if you have further questions.

1
votes

This is what I did to Build an Azure function service bus queue trigger (in Node.Js) on CI/CD pipeline in Azure DevOps: Before adding this to steps below after deploying the function to azure I got serviceBusTrigger is not registered error:

- script: 'func extensions install --package Microsoft.Azure.WebJobs.ServiceBus --version 3.0.0-beta8'
   displayName: 'install servicebus extension'

- script: 'func extensions install --package Microsoft.Azure.WebJobs.Script.ExtensionsMetadataGenerator --version 1.0.1'
  displayName: 'install azure WebJobs ExtensionsMetadataGenerator'


But after adding those steps as you see below, it works fine. I used this YAML on Azure DevOps Build pipeline and it worked for me:

pool:
  vmImage: windows-2019
  demands: npm

steps:
- script: 'func extensions install --package Microsoft.Azure.WebJobs.ServiceBus --version 3.0.0-beta8'
   displayName: 'install servicebus extension'

- script: 'func extensions install --package Microsoft.Azure.WebJobs.Script.ExtensionsMetadataGenerator --version 1.0.1'
  displayName: 'install azure WebJobs ExtensionsMetadataGenerator'

- task: NodeTool@0
  inputs:
    versionSpec: '10.x'

- task: Npm@1
  displayName: 'npm install'
  inputs:
    command: install

- task: Npm@1
  displayName: 'npm az core tools'
  inputs:
    command: custom
    verbose: false
    customCommand: 'i -g azure-functions-core-tools@core --unsafe-perm t'

- task: PublishTestResults@2
  inputs:
    testResultsFiles: '**/TEST-RESULTS.xml'
    testRunTitle: 'Test results for JavaScript'
  condition: succeededOrFailed()

- task: ArchiveFiles@2
  inputs:
    rootFolderOrFile: '$(System.DefaultWorkingDirectory)'
    includeRootFolder: false
    archiveFile: "$(System.DefaultWorkingDirectory)/FunctionApp.zip"

- task: CopyFiles@2
  inputs:
    SourceFolder: '$(System.DefaultWorkingDirectory)'
    TargetFolder: '$(Build.ArtifactStagingDirectory)'

- task: PublishBuildArtifacts@1
  inputs:
    PathtoPublish: "$(Build.ArtifactStagingDirectory)"
    ArtifactName: "drop"