0
votes

I'm trying to follow the documentation to write a message to an Azure Service Bus queue from an Azure Function (https://docs.microsoft.com/en-us/azure/azure-functions/functions-bindings-service-bus-output?tabs=csharp).

I started off with the "File->New Project" for an HTTP Trigger and added the binding:

[FunctionName("Message")]
[return: ServiceBus("namequeue")]
public static async Task<string> Run(
    [HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = null)] HttpRequest req,
    ILogger log)
{
    log.LogInformation("C# HTTP trigger function processed a request.");

    string requestBody = await new StreamReader(req.Body).ReadToEndAsync();
    dynamic data = JsonConvert.DeserializeObject(requestBody);
    string name = data?.name ?? "DefaultName";

    return name;
}

My host.json and local.settings.json file contains:

"extensions": {
    "serviceBus": {
        "prefetchCount": 100,
        "messageHandlerOptions": {
            "autoComplete": true,
            "maxConcurrentCalls": 32,
            "maxAutoRenewDuration": "00:05:00"
        },
        "sessionHandlerOptions": {
            "autoComplete": false,
            "messageWaitTimeout": "00:00:30",
            "maxAutoRenewDuration": "00:55:00",
            "maxConcurrentSessions": 16
        },
        "batchOptions": {
            "maxMessageCount": 1000,
            "operationTimeout": "00:01:00",
            "autoComplete": "true"
        }
    }
},
"Values": {
    "AzureWebJobsServiceBus": "Endpoint=<redacted>"
}

When running locally I get a timeout exception (which might be a corporate firewall).

When deployed to Azure, I can POST to the function, get a 204 reply, but no messages are added to the queue.

I think I've missed a key step as my function.json in the Azure Portal has:

{
  "generatedBy": "Microsoft.NET.Sdk.Functions-3.0.13",
  "configurationSource": "attributes",
  "bindings": [
    {
      "type": "httpTrigger",
      "methods": [
        "post"
      ],
      "authLevel": "anonymous",
      "name": "req"
    }
  ],
  "disabled": false,
  "scriptFile": "../bin/AppMapServiceBusCreate.dll",
  "entryPoint": "AppMapServiceBus.CreateMessageFunction.Run"
}

And when I click on Integration within the Portal there are no output and adding one gives me a warning of "In order to see the entire list of available function templates, you must set up extension bundles for your app.".

I thought Extension Bundles were non .NET code and the fact I've added the following via NuGet did the same thing?

<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.ServiceBus" Version="4.3.0" />

If that's accurate, how/what do I add to the function.json?

1
Did you add the AzureWebJobsServiceBus configuration setting to the function in the portal?Noah Stahl
I have now added it and it works! Thank you. I thought that's what the host.json file was for?!andomeda
Great. I added as answer for future reference :).Noah Stahl

1 Answers

0
votes

For Azure Functions using an output trigger to write to Service Bus, you'll need to add the connection string as an application setting in the function's configuration. By default, the expected setting name is AzureWebJobsServiceBus:

enter image description here