0

I have a service bus trigger function where I want to load the topic name from config

I have seen this post and I have tried the same approach Previous Question

 public async Task MyFunctionAsync(
   [ServiceBusTrigger("%TopicName%", "data-subscription", Connection = "event-bus-connection")]
   string mySbMsg)
   {
   }

In my localsettings.json file I have

"bindings": [
    {
      "%TopicName%": "topic"
    }
  ]

"bindings": [ { "%TopicName%": "rockit-notification-topic" } ]

This doesnt work

Microsoft.Azure.WebJobs.Host: Error indexing method 'MyFunction'. Microsoft.Azure.WebJobs.Host: '%TopicName%' does not resolve to a value.

Also, even if this did work, how do I add this to the settings of the function within the portal as this is an item in an array?

Paul
  • 2,773
  • 7
  • 41
  • 96

1 Answers1

1

You shouldn't add the "bindings" section to you localsettings file. localsettings.json should look something like that:

{
  "IsEncrypted": false,
  "Values": {
    "AzureWebJobsStorage": "UseDevelopmentStorage=true",
    "FUNCTIONS_WORKER_RUNTIME": "dotnet",
    "event-bus-connection": "test",
    "TopicName":"topic",
    "SubsriptionName":"data-subscription"
  }
}

On Azure Portal you can directly add it to App Service/Function Configuration like properies with name TopicName, SubsriptionName etc.

Paul
  • 2,773
  • 7
  • 41
  • 96
vshandra
  • 148
  • 1
  • 7
  • ok I will try this but without putting any %% marks how can it tell the difference between TopicName being a topic called TopicName, or a config setting? – Paul Sep 29 '21 at 13:01
  • 1
    @Paul your function declaration with %% is actually correct. %TopicName% - means that value should be retrieved from config. TopicName - means that the Topic name is 'TopicName' – vshandra Sep 29 '21 at 13:20