With the previous version 2.3.0 of webjob explicit deadletter was possible.
Below is the sample code
using System;
using System.IO;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Azure.ServiceBus;
using Microsoft.Azure.WebJobs;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
using Newtonsoft.Json;
public static class Program
{
static ISubscriptionClient subscriptionClient;
public static void Main()
{
var builder = new HostBuilder();
builder.ConfigureAppConfiguration(c =>
{
c.AddJsonFile("appsettings.json");
});
builder.ConfigureWebJobs(b =>
{
b.AddAzureStorageCoreServices();
b.AddServiceBus(sbOptions =>
{
sbOptions.MessageHandlerOptions.AutoComplete = false;
sbOptions.MessageHandlerOptions.MaxConcurrentCalls = 5;
});
});
var host = builder.Build();
using (host)
{
host.Run();
}
}
public static async Task ProcessQueueMessage(
[ServiceBusTrigger("topic_name", "subscription_name")] Message message, TextWriter log)
{
subscriptionClient = new SubscriptionClient("connection_string", "topic_name", "subscription_name");
await subscriptionClient.DeadLetterAsync(message.SystemProperties.LockToken);
await subscriptionClient.CloseAsync();
}
}
with previous webjob(version 2.3.0) JobHostConfiguration() explicit deadletter was possible and with the latest version 3.0.16 using HostBuilder() explicit deadletter is not happening, it retries till max delivery count is reached and then sends message to deadletter which should not be the intended behavior, as soon as DeadLetterAsync() is called the message should go to deadletter. It is observed in both .net framework as well as .net core. Also without using webjob configuration explicit deadlettering can be achieved by using MessageHandlerOptions. Could you please let me know how to deadletter explicitly with latest version of webjob configuration.
Explicit dead-lettering is Azure Service Bus SDK functionality and not WebJobs. You still can do that but using the MessageReceiver
which would need to be specified in the function signature. All the operations on the message are done via message receiver in the ASB SDK track 2. Here's an example.