![]() ![]() Let’s talk through these and how they fit in this solution. MassTransit and MediatR and FluentValidation If you missed it, you can go back to that post here. In part 1 of MassTransit and MediatR, we looked at the initial set up and in part 2, we looked at how we can configure MassTransit to do exponential retries when working with Service Bus. We’ll use MediatR pipeline behaviours, FluentValidation and MassTransit so it’ll be an interesting post. With Service Bus, MassTransit won’t technically dead letter an invalid message but we can get it to move it to an error queue which has the same effect. We may receive a message and it’s invalid but we don’t want to just throw an exception and retry the message till all the retries are exhausted as the message will never be processed. The redelivery filter in MassTransit is similar to what you're suggesting in your requirements, so you might look at how that works as well.In this post, we’ll look at how we can get MassTransit to dead letter invalid messages. Both handle exceptions differently, but the trick is to intercept the consume context (like is done with the Retr圜onsumeContext) to prevent the NotifyFault() from getting down to the ReceiveContext. Look at how the RetryFilter (in GreenPipes) works, and how the RescueFilter works. You are receiving this because you were mentioned. You just need to ensure to add filters in the correct order so your filter would be inner to the retry filter. If you don't rethrow, the retry filter won't be triggered. ![]() So if your filter is there and you catch the exception you need - you can do whatever you want with it. when the next call fails in the pipe, the exception is conveyed back to the caller, following the pipe backwards. Reply to this email directly, view it on GitHub, or mute the thread. You are receiving this because you authored the thread. * test MyEventConsumer and IBusinessExceptionHandler independently * share MyBusinessException like you wanted to * keep publishing Fault and retrying (and eventually reaching error queue) on exceptions that occured out of your control Will be successful in both cases but will behave like faulted in case of other Exception Public Task Consume(ConsumeContext context) Public MyEventConsumer(IBusinessExceptionHandler handler) I would keep it as close as possible to execution logic. Subject: Re: Question: Can you recover from an exception thrown in a consumer in a message filter? ( #1434)Īny reason why you want to scatter your logic around like that?įrom my understanding you are throwing exception as a part of some sort of business logic. These are excellent well thought out libraries. Actually looking to use GP elsewhere as a matter of interest. Really like the GreenPipes underpinning of MT and was trying to use every inch of it. I do understand exception handling can be taken care of in the consumer or the retry configurator, but with retry being a configuration method, injecting policy into it is non-trivial. So ideally in filters, if a send throws an exception it would be great to be able to handle it in the pipeline and take some compensating action or alternate action and not generate a faulted message delivery. I can extend a bunch of classes “handlers” to deal with delayed retries, but it is just cleaner to plug functionality in the pipeline. So the “business” functionality you are referencing is actually higher level plumbing and framework code. large message handling, failed message handling, etc. ![]() It allows different features to be opted into e.g. It includes automatically creating and wiring up handlers and managing routing in a fluent style. We therefore have business and transport tiers, and MT is a deep form of transport. We have created a framework around MT that completely abstracts bus-mechanics from the engineers so they can focus on business code. I agree with you conceptually, but in this case there are reasons (little hard to explain without publishing a ton of code that is private, but I will try). Thank you for engaging with your guidance. ![]()
0 Comments
Leave a Reply. |