A compact, opinioned but extensible .Net Standard SDK for Azure Service Bus which aims to tackle the cross-cutting concerns of:
- Deserialisation: Extensible IMessageSerialiser to derive an instance of your TMessage from a Message with built-in JSON deserialisation using JsonMessageSerialiser
- Handler dispatching: Extensible IMessageProcessorDispatcher for dispatching your IMessageHandler implementation with built-in property based dispatching using MessagePropertyBasedDispatcher
- Logging: Uses ILogger methods from Microsoft.Extensions.Logging with built-in Application Insights tracing
- Telemetry: Extensible IInstrumentor to measure elapsed handling with built-in Application Insights metric tracking
- Exception handling: Handles common problems with message handling by abandoning or dead-lettering messages with enriched properties explaining the outcome
- Install the package
AzureBusDepot
from nuget - Define implementations of IMessageHandler<TMessage> for your message types (see sample)
- Define implementations of IEndpointHandlingConfig for every Azure Service Bus endpoint you want to to listen to. As a consumer it is a bit of work but these unique config types are required to play nice with dependency injection and reduces a whole lot of boilerplate bootstrapping code.
Add the following to ConfigureServices((hostContext, services) =>{...})
of a Generic HostBuilder.
services
.AddAzureBusDepot<JsonMessageSerialiser>()
.ConfigureSingleMessageTypeListener<MyEndpointHandlingConfig, MyEvent, MyEventHandler>(endpointConfig)
.AddApplicationInsights(appInsightsOptions);
Add the following to ConfigureServices((hostContext, services) =>{...})
of a Generic HostBuilder.
services
.AddAzureBusDepot<JsonMessageSerialiser>()
.ConfigureMessageListenerWithPropertyBasedDispatcher(
endpointConfig, "NServiceBus.EnclosedMessageType")
.AddMessageHandler<MyEvent, MyEventHandler>()
.AddMessageHandler<MyOtherEvent, MyOtherEventHandler>()
.AddApplicationInsights(appInsightsOptions);
Samples can be found under the samples folder.
Please see the contributing document.