Zwergenland.CleanMessageBus.Abstractions
1.2.1
dotnet add package Zwergenland.CleanMessageBus.Abstractions --version 1.2.1
NuGet\Install-Package Zwergenland.CleanMessageBus.Abstractions -Version 1.2.1
<PackageReference Include="Zwergenland.CleanMessageBus.Abstractions" Version="1.2.1" />
<PackageVersion Include="Zwergenland.CleanMessageBus.Abstractions" Version="1.2.1" />
<PackageReference Include="Zwergenland.CleanMessageBus.Abstractions" />
paket add Zwergenland.CleanMessageBus.Abstractions --version 1.2.1
#r "nuget: Zwergenland.CleanMessageBus.Abstractions, 1.2.1"
#:package Zwergenland.CleanMessageBus.Abstractions@1.2.1
#addin nuget:?package=Zwergenland.CleanMessageBus.Abstractions&version=1.2.1
#tool nuget:?package=Zwergenland.CleanMessageBus.Abstractions&version=1.2.1
CleanMessageBus
This package provides an abstraction around message busses for easy integration of events. Currently the following message brokers are supported:
- RabbitMQ
Publishing Events
Event object must implement marker interface
IIntegrationeventfor integration events otIDomainEventfor domain eventsInject
IMessageBusto desired servicePublish event by using
IMessageBus.PublishAsync(integrationEvent)Automatic creation of producer resource on message bus (for example exchange for rabbitmq)
Example:
public record UserRegisteredEvent(string Username, string Email) : IIntegrationevent;
var integrationEvent = new UserRegisteredEvent("JohnDoe", "john@doe.com");
await messageBus.PublishAsync(integrationevent);
Change producer name
- Use attribute
[Produces(Name="ProducerName")]to set producer name
Handling Events
- Handler must inherit from
IntegrationEventHandlerBase<TIntegrationEvent>class for integration events or fromDomainEventHandlerBase<TDomainEvent>for domain events - Generic type specifies domain event type to receive
- Implementation logic must be implemented in the
Handlemethod - Registration happens automatically via dependency injection
- Automatic creation of consumer resource on message bus (for example queue for rabbitmq)
- Integration of CleanDomainValidation result types
Example:
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 consumer name
- Use attribute
[ConsumedBy(Name="ConsumerName")]to set consumer name - Not allowed for domain events!
Change producer name
- Use attribute
[ProducedBy(Name="ProducerName")]to set producer name
Throttle message rate
- Use attribute
[Throttled(RequestInterval=1000)]to set message processing interval - Message bus waits specified time (in ms) before processing the next event
Configuration via dependency injection
- Define assemblies containing events and handlers
- Select and configure message broker
Example:
builder.Services.AddCleanMessageBus(config => config
.RegisterIntegrationEventsFromAssembly(Assembly.GetExecutingAssembly())
.RegisterDomainEventsFromAssemby(Assembly.GetExecutingAssembly())
.RegisterHandlersFromAssemby(Assembly.GetExecutingAssembly()
.UseRabbitMq(rabbitConfig => rabbitConfig
.WithHostname("localhost")
.WithCredentials("username", "password")
.UseSsl())));
| 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 was computed. 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 was computed. 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. |
-
net8.0
- Microsoft.Extensions.DependencyInjection (>= 10.0.1)
- Zwergenland.CleanDomainValidation (>= 1.1.1)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Zwergenland.CleanMessageBus.Abstractions:
| Package | Downloads |
|---|---|
|
Zwergenland.CleanMessageBus.RabbitMQ
RabbitMQ message bus implementation for easy integration of events |
GitHub repositories
This package is not used by any popular GitHub repositories.