WorkR.Triggers.AzureServiceBus 0.3.3

dotnet add package WorkR.Triggers.AzureServiceBus --version 0.3.3
                    
NuGet\Install-Package WorkR.Triggers.AzureServiceBus -Version 0.3.3
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="WorkR.Triggers.AzureServiceBus" Version="0.3.3" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="WorkR.Triggers.AzureServiceBus" Version="0.3.3" />
                    
Directory.Packages.props
<PackageReference Include="WorkR.Triggers.AzureServiceBus" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add WorkR.Triggers.AzureServiceBus --version 0.3.3
                    
#r "nuget: WorkR.Triggers.AzureServiceBus, 0.3.3"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package WorkR.Triggers.AzureServiceBus@0.3.3
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=WorkR.Triggers.AzureServiceBus&version=0.3.3
                    
Install as a Cake Addin
#tool nuget:?package=WorkR.Triggers.AzureServiceBus&version=0.3.3
                    
Install as a Cake Tool

WorkR.Triggers.AzureServiceBus

.NET NuGet License: MIT

Azure Service Bus trigger for WorkR. Processes messages from a queue or topic subscription and drives them through a composable worker pipeline.


Installation

dotnet add package WorkR.Triggers.AzureServiceBus

AddServiceBusWorker

Deserialise Service Bus messages to a strongly-typed model before passing them to your worker. JSON deserialisation is used by default.

public class OrderCreatedWorker : IWorker<ServiceBusTriggerContext<OrderCreated>>
{
    public async Task ExecuteAsync(
        ServiceBusTriggerContext<OrderCreated> context,
        CancellationToken cancellationToken)
    {
        var order = context.Value;  // deserialized OrderCreated

        // process the order...

        await context.Args.CompleteMessageAsync(context.Args.Message, cancellationToken);
    }
}

builder.Services.AddServiceBusWorker<OrderCreated, OrderCreatedWorker>(
    sp => sp.GetRequiredService<ServiceBusClient>(),
    "orders");

Typed messages — topic subscription

builder.Services.AddServiceBusWorker<OrderCreated, OrderCreatedWorker>(
    sp => sp.GetRequiredService<ServiceBusClient>(),
    topicName: "orders",
    subscriptionName: "fulfillment");

Raw messages

Receive the raw ProcessMessageEventArgs without deserialisation:

public class RawWorker : IWorker<ServiceBusTriggerContext>
{
    public async Task ExecuteAsync(
        ServiceBusTriggerContext context,
        CancellationToken cancellationToken)
    {
        var args = context.Value;  // ProcessMessageEventArgs
        var body = args.Message.Body.ToString();

        await args.CompleteMessageAsync(args.Message, cancellationToken);
    }
}

builder.Services.AddServiceBusWorker<RawWorker>(
    sp => sp.GetRequiredService<ServiceBusClient>(),
    "my-queue");

Worker Contract

Workers must either return a completed task or throw — the trigger does not impose any settlement outcome. Message settlement (complete, abandon, dead-letter, defer) is the worker's responsibility via context.Args. If no settlement is performed the SDK's default behaviour applies (controlled by ServiceBusProcessorOptions.AutoCompleteMessages, which defaults to true).

ServiceBusTriggerContext

The context passed to your worker for each message.

Member Description
Value The deserialised message body (T for typed, ProcessMessageEventArgs for raw)
Args The raw ProcessMessageEventArgs (typed variant only)
ExecutionId Unique identifier for this pipeline invocation
OccurredAt When the message was received

Message settlement (complete, abandon, dead-letter, defer) is performed directly via Args:

await context.Args.CompleteMessageAsync(context.Args.Message, cancellationToken);
await context.Args.AbandonMessageAsync(context.Args.Message, cancellationToken: cancellationToken);
await context.Args.DeadLetterMessageAsync(context.Args.Message, cancellationToken: cancellationToken);

Custom Deserialiser

Supply a custom deserialiser to control how message bodies are converted to your model:

builder.Services.AddServiceBusWorker<OrderCreated, OrderCreatedWorker>(
    sp => sp.GetRequiredService<ServiceBusClient>(),
    "orders",
    deserializerFactory: sp => async args =>
    {
        var json = args.Message.Body.ToString();
        return JsonSerializer.Deserialize<OrderCreated>(json, myOptions)!;
    });

The built-in JSON deserialiser can also be configured with custom JsonSerializerOptions:

deserializerFactory: _ => ServiceBusMessageDeserializers.Json<OrderCreated>(myJsonOptions)

Processor Options

WorkR creates a ServiceBusProcessor using the Azure SDK's default ServiceBusProcessorOptions. Pass a configure delegate to override any of these:

builder.Services.AddServiceBusWorker<OrderCreated, OrderCreatedWorker>(
    sp => sp.GetRequiredService<ServiceBusClient>(),
    "orders",
    configure: options =>
    {
        options.MaxConcurrentCalls = 4;
        options.AutoCompleteMessages = false;
    });

See ServiceBusProcessorOptions for the full list of available options and their defaults.


Full Pipeline Control

Use the builder overload to chain multiple workers or configure per-step middleware:

builder.Services.AddServiceBusWorker<OrderCreated>(
    sp => sp.GetRequiredService<ServiceBusClient>(),
    "orders",
    pipeline => pipeline
        .AddWorker<ValidateWorker, ValidatedOrder>()
        .AddWorker<PersistWorker>());

Topic/subscription variant:

builder.Services.AddServiceBusWorker<OrderCreated>(
    sp => sp.GetRequiredService<ServiceBusClient>(),
    topicName: "orders",
    subscriptionName: "fulfillment",
    pipeline => pipeline
        .AddWorker<ValidateWorker, ValidatedOrder>()
        .AddWorker<PersistWorker>());

Default middleware: UseScope. Applied to the first worker in the chain only.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.3.3 41 5/28/2026
0.3.2-preview 42 5/28/2026
0.2.1 95 5/22/2026
0.1.7-g2e3259f211 93 5/19/2026
0.1.4 92 5/22/2026
0.0.6-preview 41 5/28/2026
0.0.5-preview 37 5/28/2026