I am in the process of upgrading an Azure Web Job with a Queue Trigger from 2.2 to 3.0.4. I added the storage extension Nuget package, changed the configuration code and got the application to run.
It is able to pull from the queue, but I am not able to see any errors nor hit any breakpoints locally in my queue trigger function. I know that the messages are being picked up because it is the only application pointed to my local storage emulator (with a unique queue name) and all messages go straight to poison queue a few seconds after being added. I never see an error in the console though.
I am using Autofac, as the 2.2 implementation worked fine with it - I included the Autofac.Extensions.DependencyInjection package.
Here is my main in program.cs - breakpoints hit fine inside here, but not in the QueueProcessor:
static void Main()
{
Console.ForegroundColor = ConsoleColor.Yellow;
Console.Write("Initializing DI container...");
var containerBuilder = new ContainerBuilder();
RegisterTypes(containerBuilder);
containerBuilder.RegisterType<BulkUpdateRequestProcessor>();
containerBuilder.Build();
Console.Write("done.");
Console.WriteLine();
Console.Write("Initializing host configuration...");
var hostBuilder = new HostBuilder();
hostBuilder.ConfigureWebJobs(b =>
{
b.AddAzureStorageCoreServices()
.AddAzureStorage(options =>
{
options.BatchSize = 1;
options.MaxDequeueCount = 1;
options.MaxPollingInterval = TimeSpan.FromSeconds(5f);
});
b.AddTimers();
b.AddExecutionContextBinding();
b.AddDashboardLogging();
})
.ConfigureServices((x) => x.AddAutofac())
.UseConsoleLifetime();
Console.Write("done.");
Console.WriteLine();
Console.ForegroundColor = ConsoleColor.Green;
var host = hostBuilder.Build();
using (host)
{
host.Run();
}
}
Queue Processor:
public class BulkUpdateRequestProcessor
{
private readonly IRevisionService _revisionService;
private readonly ILogger _logger;
private readonly IClock _clock;
public BulkUpdateRequestProcessor(IRevisionService revisionService, ILogger logger, IClock clock)
{
_revisionService = revisionService;
_logger = logger;
_clock = clock ?? throw new ArgumentNullException(nameof(clock));
}
public async Task ProcessNewJobRequest([QueueTrigger(BulkUpdateConstant.BULK_UPDATE_JOB_QUEUE)] Guid jobId, TextWriter log)
{
_logger.Info(string.Format("New item appeared in a queue: '{0}'", jobId));
try
{
await ProcessJobRequest(jobId);
}
catch (Exception ex)
{
_logger.Log(NLog.LogLevel.Error, ex);
await TryNotifyJobFailed(jobId, ex.Message);
throw;
}
_logger.Info(string.Format("Request '{0}' processed", jobId));
}
}
It turns out that the class containing Web Job bindings require a zero parameter constructor. I found this out by accident though. It would be nice if a build error would have occurred. -1 Microsoft