Is there a way to create and register a generic IFailed that would catch second level retries that have no handlers?
We use second-level retries enabled and have our handlers implementing IHandleMessages<SomeCommand> as well as IHandleMessages<IFailed<SomeCommand>>.
However, not all our handlers are implementing the IFailed<SomeCommand> interface and this is causing some exceptions to bubble up multiple times when SomeCommand fails.
Is there a way to register a generic IHandleMessages<IFailed<T>> that will handle all failed commands that have not been handled properly?
I'm thinking of at least logging T has failed and we will not attempt second level retries or something similar if the command has failed.
Yes there is
To get to handle all failed messages, you can simply register a handler that implements
IHandleMessages<IFailed<object>>.If you want it to be a "fallback" (i.e. only be used when there's no explicit handler for a given failed messages type), then you can decorate Rebus'
IHandlerActivatorand filter the returned handlers.Here's how:
Create an extension method with a handler activator decorator
and then ensure that second level retries and your fallback mechanism are enabled
You can see a full example here: https://github.com/rebus-org/Rebus.ServiceProvider/blob/master/Rebus.ServiceProvider.Tests/Examples/AddMessageHandlerFallback.cs