CleanMessageBus.Abstractions
2.0.1
dotnet add package CleanMessageBus.Abstractions --version 2.0.1
NuGet\Install-Package CleanMessageBus.Abstractions -Version 2.0.1
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="CleanMessageBus.Abstractions" Version="2.0.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="CleanMessageBus.Abstractions" Version="2.0.1" />
<PackageReference Include="CleanMessageBus.Abstractions" />
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 CleanMessageBus.Abstractions --version 2.0.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: CleanMessageBus.Abstractions, 2.0.1"
#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 CleanMessageBus.Abstractions@2.0.1
#: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=CleanMessageBus.Abstractions&version=2.0.1
#tool nuget:?package=CleanMessageBus.Abstractions&version=2.0.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
CleanMessageBus
This package provides an abstraction layer for message busses for easy integration of events.
Publishing Events
Event object must inherit from class
Integrationeventfor integration events otDomainEventfor domain eventsInject
IMessageBusto desired servicePublish event by using
IMessageBus.PublishAsync(event)Automatic creation of producer resource on message bus
Example:
public class UserRegisteredEvent(string Username, string Email) : Integrationevent;
var integrationEvent = new UserRegisteredEvent("JohnDoe", "john@doe.com");
await messageBus.PublishAsync(integrationevent);
Change event name name
- Use attribute
[EventName(<Name>)]to set producer name
Handling Events
- Handler must inherit from
IntegrationEventHandlerBase<TIntegrationEvent>class for integration events or fromDomainEventHandlerBase<TDomainEvent>for domain events - Integration event handlers must specify the name of the application, that published the event using the
[SourceApplication(<Name>)]attribute. This is not allowed for domain event handlers, as the application of the event and the event handler must match. - Generic type specifies domain event type to receive
- Implementation logic must be implemented in the
Handlemethod - Registration happens automatically via dependency injection
- Integration of CleanDomainValidation result types
Example:
[SourceApplication("MyApp.Authorization")]
public class UserRegisteredEventHandler : IntegrationEventHandlerBase<UserRegisteredEvent>
{
public override async Task<CanFail> Handle(UserRegisteredEvent @event, CancellationToken cancellationToken)
{
Console.WriteLine($"User {@event.Username} with email {@event.Email} has been registered.");
//TODO furhter logic in here
return CanFail.Success;
}
}
Change event handler name
- Use attribute
[EventHandlerName(<Name>)]to set event handler name
Use serialized message handling
- Ideal for long running / rate limited tasks, that should be split across multiple instances
- Use attribute
[Serialized(MaxQueueSize = 1)]to set the max amount of messages that is being loaded in the application simultaniously - Event handlers with this attribute are only called if the previous handler has completed processing the event
- Rate limiting may be implemented in the handler itself
Configuration via dependency injection
- Define assemblies containing events and handlers
- Define name of the current application (defaults to name of the entry assembly)
- Select and configure message broker
Example:
builder.Services.AddCleanMessageBus(config => config
.WithApplicationName("MyApp")
.RegisterIntegrationEventsFromAssembly(Assembly.GetExecutingAssembly())
.RegisterDomainEventsFromAssemby(Assembly.GetExecutingAssembly())
.RegisterHandlersFromAssemby(Assembly.GetExecutingAssembly())
.Use... //Use concrete implementation like rabbbitmq
| 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. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net10.0
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.9)
- Zwergenland.CleanDomainValidation (>= 1.1.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.