Brer 1.1.0
dotnet add package Brer --version 1.1.0
NuGet\Install-Package Brer -Version 1.1.0
<PackageReference Include="Brer" Version="1.1.0" />
paket add Brer --version 1.1.0
#r "nuget: Brer, 1.1.0"
// Install Brer as a Cake Addin #addin nuget:?package=Brer&version=1.1.0 // Install Brer as a Cake Tool #tool nuget:?package=Brer&version=1.1.0
Brer
A rabbitMQ library for ASP.NET.
Special thanks to Marco Pil
How do i use Brer?
Brer makes use of a hostedservice in ASP.NET.
A basic brer startup example can be found here.
Initial Setup
In short one must register the Brer services as follows:
services.UseBrer(
new BrerOptionsBuilder().WithAddress(BrerOptionsBuilder.localHost, BrerOptionsBuilder.defaultPort)
.WithPassword(BrerOptionsBuilder.defaultLogin)
.WithUsername(BrerOptionsBuilder.defaultLogin)
.WithExchange("MyExchange")
.WithQueueName("MyQueue")
.Build()
);
Brer can also be configured using environment variables as follows:
services.UseBrer(new BrerOptionsBuilder().ReadFromEnviromentVariables().Build());
Where it will look for the following variables:
BrerHostName
BrerPort
BrerExchangeName
BrerQueueName
BrerUserName
BrerPassword
- Optionally :
BrerMaxRetries
see DLX in Brer
Registering/Decorating an EventListener
Brer will automatically scan all referencing assemblies for EventListeners.
Once a class is annoted with the EventListener
attribute it will further scan the class for Handler
or
WildCardHandler
.
If Listeners collide on topic names Handler
will always take priority over WildCardHandler
.
Handler
[EventListener]
public class MyEventHandler{
[Handler(topic:"MyTopic")]
public async Task Handle(MyEvent @event){
// do stuff
}
}
WildCardHandler
When using a WildCardHandler you're required to use at least 1 wild card in the topic binding.
Wild cards can contain as many * as wanted but impose some restrictions on the usage of #. Only 1 # can be used somewhere in the middle of a topic name and 1 the end. if you require more it's likely best to re-evaluate the topic naming or simply use *.
A valid format would be:
MyGarage*.Rental.Cars.#.Internal.*.#
#
- etc
An invalid format would be:
MyGarage.#.Cars.#.Internal.*.#
We use two #'s in the middle of the topic here which is not allowed.
[EventListener]
public class MyEventHandler{
[WildCardHandler("MyTopic.#")]
public async Task Handle(MyEvent @event){
// do stuff
}
}
Publishing events.
To publish an event simply inject the IBrerPublisher
into your class.
public class MyEventPublisher{
private readonly IBrerPublisher _brerPublisher;
MyEventPublisher(IBrerPublisher brerPublisher){
_brerPublisher = brerPublisher;
}
PublishEvent(){
_brerPublisher.Publish("MyTopic", MyEvent)
}
}
Error handling.
Brer adds some message headers to give insights into exceptions and requeue counts.
These headers are:
x-Brer-Exception
x-Brer-Exception-Message
x-Brer-Exception-StackTrace
x-Brer-RequeueCount
Note: that these get overwritten if an error gets thrown again whilst re-processing.
DLX (Dead Letter Exchange) / Poison Queue
Brer can be configured to send messages to a DLX one can either provide the env var BrerMaxRetries
when using env vars
or use WithMaxRetries(5)
Brer does not try to infer any dlx naming or allowing for customization.
It will always use the provided exchange and queue name for dlx routing f.e.:
important to note Brer will create the (persistent) queue for you but AND the exchange if you do not make sure the user has correct permissions before-hand messages will be dropped.
Brer Variable | Name | DLX Name | RabbitmqHeader |
---|---|---|---|
BrerExchangeName | my-company-exchange | my-company-exchange-dlx | x-dead-letter-exchange |
BrerQueueName | my-service-queue | my-service-queue-dlx | x-dead-letter-routing-key |
I want to contribute!
As of now we'd greatly appreciate adding support for different exchange types.
notes:
- No global usings
- Use SonarLint
- Rider/ReSharper default styling preferred
I'm missing a feature!
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. 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. |
-
net6.0
- Microsoft.AspNetCore.Hosting.Abstractions (>= 2.2.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 8.0.1)
- Microsoft.Extensions.DependencyModel (>= 8.0.0)
- Newtonsoft.Json (>= 13.0.3)
- RabbitMQ.Client (>= 6.8.1)
-
net8.0
- Microsoft.AspNetCore.Hosting.Abstractions (>= 2.2.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 8.0.1)
- Microsoft.Extensions.DependencyModel (>= 8.0.0)
- Newtonsoft.Json (>= 13.0.3)
- RabbitMQ.Client (>= 6.8.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.