EasyDeadLetterStrategy 1.1.2
See the version list below for details.
dotnet add package EasyDeadLetterStrategy --version 1.1.2
NuGet\Install-Package EasyDeadLetterStrategy -Version 1.1.2
<PackageReference Include="EasyDeadLetterStrategy" Version="1.1.2" />
paket add EasyDeadLetterStrategy --version 1.1.2
#r "nuget: EasyDeadLetterStrategy, 1.1.2"
// Install EasyDeadLetterStrategy as a Cake Addin #addin nuget:?package=EasyDeadLetterStrategy&version=1.1.2 // Install EasyDeadLetterStrategy as a Cake Tool #tool nuget:?package=EasyDeadLetterStrategy&version=1.1.2
π±Easy Dead-Letter π±
πHandling dead-letter queues in EasyNetQ (RabbitMQ)
Messages from a queue can be "dead-lettered"; that is, republished to an exchange when any of the following events occur:
- The message is negatively acknowledged by a consumer using basic.reject or basic.nack with requeue parameter set to false.
- The message expires due to per-message TTL;
- The message is dropped because its queue exceeded a length limit
π Problem
If you are using RabbitMQ client for dotnet there is no problem, you can define dead-letter queues during a queue declaration, But using RabbitMQ client brings lots of implementation complexity to the application, because of that so many developers prefer to use the EasyNetQ library which is a wrapper on RabbitMQ client(Amazing and simple). There is no implementation for dead-letter queues in EasyNetQ to keep the library easy to use, It means in case of any exception in the message consumers, the message will be moved to the default error queue of RabbitMQ, and for an enterprise application, it's not good idea to keep all the failure messages in one queue, because maybe different handling mechanism needs to be applied to those failed messages according to the type of the message.
π Solution
In one of my projects there was a requirement to handle failed messages discretely and moving each failed message to the related dead-letter queue. For example, if there is a queue named Product.Report, in case of any exception the message should be moved to a new queue named Product.Report.deadletter. Of course this deadletter queue is a typical queue with the same message type, in order to consume them with another approach. This functionality can be achieved via the EasyDeadLetter NuGet package. you can find it on Nuget website.
πHow it works
- First of all, Decorate your class object with QeueuAttribute
[Queue("Product.Report", ExchangeName = "Product.Report")]
public class ProductReport { }
- The second step is to define your dead-letter queue with the same QueueAttribute and also inherit the dead-letter object from the Main object class.
[Queue("Product.Report.DeadLetter", ExchangeName = "Product.Report.DeadLetter")]
public class ProductReportDeadLetter : ProductReport { }
- Now, it's time to decorate your main queue object with the EasyDeadLetter attribute and set the type of dead-letter queue.
[EasyDeadLetter(DeadLetterType = typeof(ProductReportDeadLetter))]
[Queue("Product.Report", ExchangeName = "Product.Report")]
public class ProductReport { }
- In the final step, you need to register EasyDeadLetterStrategy as the default error handler (IConsumerErrorStrategy) in the startup.cs
services.AddSingleton<IBus>(RabbitHutch.CreateBus("connectionString",
serviceRegister =>
{
serviceRegister.Register<IConsumerErrorStrategy, EasyDeadLetterStrategy>();
}));
That's all. from now on any failed message will be moved to the related dead-letter queue
Note: Take it into consideration :
- The main queue object is decorated by the EasyDeadLetter attribute
- Register EasyDeadLetterStrategy as the default ErrorHandler
- any object which is not decorated with the EasyDeadLetter will be handled by the default mechanism of the EasyNetQ and RabbitMQ (will be saved into the default error queue).
- In case of any exception in this NuGet package, the message will be moved to the default error queue. and there is an Exception property for each message in this queue, which can be checked, and find the root cause of the issue.
Feel free to send me your opinion. π ππ±
Read my article on Medium about this package : Medium Link
You can download the Nuget package from Here
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. 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 was computed. 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. |
.NET Core | netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.1 is compatible. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.1
- EasyNetQ (>= 6.3.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.