2

I have a queue processing application which is workign fine. I am now trying to persuade the queue trigger to only process one item at a time. My host.json is set up correctly, I think:

enter image description here

But when I run the app (either in Azure as a web job, or locally in Visual Studio), I see this:

enter image description here

I suspect that I am missing something really obvious, so wondering whether anyone has come across this before. I have found a few articles, but nothing that gives me any insight into what I am doing wrong.

Adding the contents of program.cs. I have tried adding "host.json" after the AddAzureAppConfiguration entry, but that makes no difference.

    class Program
{
    static async Task Main()
    {
        //var builder = new HostBuilder();
        var builder = Host.CreateDefaultBuilder();

        builder.ConfigureLogging((context, a) =>
        {
            a.AddConsole();
        });

        builder.ConfigureAppConfiguration((hostContext, config) =>
        {
            config.AddUserSecrets(
                "5aa19112-5ff7-467b-b062-f37c3654872d"); // This is automatic for a web app, but not for a console app
            var settings = config.Build();
            var connectionString = settings.GetConnectionString("AzureAppConfiguration");
            config.AddAzureAppConfiguration(connectionString);
        });

        builder.ConfigureWebJobs(b =>
        {
            b.AddAzureStorageCoreServices();
            b.AddAzureStorage();
        });

        builder.ConfigureServices((hostContext, services) =>
        {
            services.AddMemoryCache();
        });

        var host = builder.Build();

        using (host)
        {
            await host.RunAsync();
        }
    }
}
Nick Locke
  • 65
  • 1
  • 6

1 Answers1

4

I think you are using the Azure WebJobs SDK v3.x. In v3.x, hosts.json does not work for WebJob.

Instead, version 3.x uses the standard ASP.NET Core APIs, so you need to configure it using the ConfigureWebJobs method:

static async Task Main()
{
    var builder = new HostBuilder();
    builder.ConfigureWebJobs(b =>
    {
        b.AddAzureStorageCoreServices();
        b.AddAzureStorage(a => {
            a.BatchSize = 8;
            a.NewBatchThreshold = 4;
            a.MaxDequeueCount = 4;
            a.MaxPollingInterval = TimeSpan.FromSeconds(15);
        });
    });
    var host = builder.Build();
    using (host)
    {
        await host.RunAsync();
    }
}

Docs: https://learn.microsoft.com/pt-pt/azure/app-service/webjobs-sdk-how-to#queue-storage-trigger-configuration

Maicon Heck
  • 2,017
  • 1
  • 20
  • 27