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
<PackageReference Include="WorkR.Triggers.AzureServiceBus" Version="0.3.3" />
<PackageVersion Include="WorkR.Triggers.AzureServiceBus" Version="0.3.3" />
<PackageReference Include="WorkR.Triggers.AzureServiceBus" />
paket add WorkR.Triggers.AzureServiceBus --version 0.3.3
#r "nuget: WorkR.Triggers.AzureServiceBus, 0.3.3"
#:package WorkR.Triggers.AzureServiceBus@0.3.3
#addin nuget:?package=WorkR.Triggers.AzureServiceBus&version=0.3.3
#tool nuget:?package=WorkR.Triggers.AzureServiceBus&version=0.3.3
WorkR.Triggers.AzureServiceBus
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
Typed messages — queue (recommended)
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 | Versions 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. |
-
net10.0
- Azure.Messaging.ServiceBus (>= 7.18.0)
- WorkR (>= 0.3.3)
-
net8.0
- Azure.Messaging.ServiceBus (>= 7.18.0)
- WorkR (>= 0.3.3)
-
net9.0
- Azure.Messaging.ServiceBus (>= 7.18.0)
- WorkR (>= 0.3.3)
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 |