0

I'm trying to follow the documentation to write a message to an Azure Service Bus queue from an Azure Function (https://learn.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?

3
  • Did you add the AzureWebJobsServiceBus configuration setting to the function in the portal? Commented Jul 28, 2021 at 13:46
  • I have now added it and it works! Thank you. I thought that's what the host.json file was for?! Commented Jul 28, 2021 at 14:04
  • Great. I added as answer for future reference :). Commented Jul 28, 2021 at 14:10

1 Answer 1

0

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.