Zwergenland.CleanMessageBus.RabbitMQ
1.2.1
dotnet add package Zwergenland.CleanMessageBus.RabbitMQ --version 1.2.1
NuGet\Install-Package Zwergenland.CleanMessageBus.RabbitMQ -Version 1.2.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="Zwergenland.CleanMessageBus.RabbitMQ" Version="1.2.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Zwergenland.CleanMessageBus.RabbitMQ" Version="1.2.1" />
<PackageReference Include="Zwergenland.CleanMessageBus.RabbitMQ" />
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 Zwergenland.CleanMessageBus.RabbitMQ --version 1.2.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Zwergenland.CleanMessageBus.RabbitMQ, 1.2.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 Zwergenland.CleanMessageBus.RabbitMQ@1.2.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=Zwergenland.CleanMessageBus.RabbitMQ&version=1.2.1
#tool nuget:?package=Zwergenland.CleanMessageBus.RabbitMQ&version=1.2.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
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. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net8.0
- Microsoft.Extensions.Hosting.Abstractions (>= 10.0.1)
- Microsoft.Extensions.Logging (>= 10.0.1)
- RabbitMQ.Client (>= 7.2.0)
- Zwergenland.CleanMessageBus.Abstractions (>= 1.2.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.