SolTechnology.Core.MessageBus
0.5.0
dotnet add package SolTechnology.Core.MessageBus --version 0.5.0
NuGet\Install-Package SolTechnology.Core.MessageBus -Version 0.5.0
<PackageReference Include="SolTechnology.Core.MessageBus" Version="0.5.0" />
<PackageVersion Include="SolTechnology.Core.MessageBus" Version="0.5.0" />
<PackageReference Include="SolTechnology.Core.MessageBus" />
paket add SolTechnology.Core.MessageBus --version 0.5.0
#r "nuget: SolTechnology.Core.MessageBus, 0.5.0"
#:package SolTechnology.Core.MessageBus@0.5.0
#addin nuget:?package=SolTechnology.Core.MessageBus&version=0.5.0
#tool nuget:?package=SolTechnology.Core.MessageBus&version=0.5.0
Overview
The SolTechnology.Core.MessageBus library provides minimal functionality needed for Azure Service Bus connection. It handles needed services registration and configuration.
Registration
For installing the library, reference SolTechnology.Core.MessageBus nuget package and invoke AddMessageBus() service collection extension method:
services.AddMessageBus();
Configuration
- The first option is to create an appsettings.json section:
"Configuration": {
"MessageBus": {
"ConnectionString": "your-service-bus-connection-string"
}
}
- Alternatevely the same settings can be provided by optional parameter during registration:
var messageBusConfiguration = new MessageBusConfiguration
{
ConnectionString = "your-service-bus-connection-string"
};
services.AddMessageBus(messageBusConfiguration);
Usage
II. Message publishing
- Register message publisher
services.AddMessageBus()
.WithPublisher<PlayerMatchesSynchronizedEvent>("synchronizeplayermatches");
Where T is a published message type and argument is a topic name.
- Inject IMessagePublisher
public SynchronizePlayerMatchesHandler(IMessagePublisher messagePublisher)
{
_messagePublisher = messagePublisher;
}
- Invoke Publish() method
var message = new PlayerMatchesSynchronizedEvent(command.PlayerId);
await _messagePublisher.Publish(message);
I. Message receiving
- Register message receiver
builder.Services.AddMessageBus()
.WithReceiver<PlayerMatchesSynchronizedEvent, CalculatePlayerStatistics>("synchronizeplayermatches", "calculatestatistics");
Where generic arguments are MessageType, MessageHandlerType class and arguments: topicName and subscriptionName.
- Make your Message Handler implement IMessageHandler<T> (where T is a MessageType)
public class CalculatePlayerStatistics : IMessageHandler<PlayerMatchesSynchronizedEvent>
- Implement Handle(T) method
public async Task Handle(PlayerMatchesSynchronizedEvent message, CancellationToken cancellationToken)
{
var command = new CalculatePlayerStatisticsCommand(message.PlayerId);
await _handler.Handle(command);
}
- What is more
- The Message Handler is registered as IHostedService
- Topics and subsriptions are created from code on registration using default values
- Message has to implement IMessage inteface
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | 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.2)
- Microsoft.Azure.ServiceBus (>= 5.2.0)
- Microsoft.Extensions.Configuration (>= 10.0.0)
- Microsoft.Extensions.Configuration.Binder (>= 10.0.0)
- Microsoft.Extensions.DependencyInjection (>= 10.0.0)
- Microsoft.Extensions.Hosting.Abstractions (>= 8.0.1)
- Microsoft.Extensions.Options (>= 10.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.