简体   繁体   中英

Unable to write message to Service Bus Queue from Azure Function

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?

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 :

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM