Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handler of all failed messages by handling IFailed<object> #22

Closed
jens-jonsson opened this issue May 29, 2019 · 6 comments
Closed

Handler of all failed messages by handling IFailed<object> #22

jens-jonsson opened this issue May 29, 2019 · 6 comments
Projects

Comments

@jens-jonsson
Copy link

Trying to create a handler to handle all failed messages by implementing IHandleMessages<IFailed<object>>.

Documentation suggests that implementing IHandleMessages<object> will call the handler for all messages but my constraint of IFailed does not seem to create a match when resolving handlers.

I am on .net core using default IServiceProvider. Checking assembly scanning shows that my handler gets registered but not called for failed messages.

@mookid8000
Copy link
Member

I'm not sure if that will work 😁

First thing to look for would be what your IoC container returns when resolving a list of IHandleMessages<IFailed<object>>

@jens-jonsson
Copy link
Author

Sorry should have been more clear on that.

Calling IServiceProvider.GetServices<IHandleMessages<IFailed<object>>>() returns a list containing an instance of my registered handler.

@mookid8000
Copy link
Member

Calling IServiceProvider.GetServices<IHandleMessages<IFailed<object>>>() returns a list containing an instance of my registered handler.

oh sorry, what I meant was this: Try and see what the container returns when resolving a list of IHandleMessages<IFailed<YourMessageType>>

@jens-jonsson
Copy link
Author

jens-jonsson commented Jun 3, 2019

IServiceProvicer.GetServices<IHandleMessages<IFailed<PublishEntityCommand>>> works fine too, returning a list with my handler in it.

Base problem seems to be that stacking generics like IMessageHandler<T> where T is IFailed<U> does not work as I thought.

I guess if IFailed<> implemented e.g. a new marker interface IFailed I could use IHandleMessages<IFailed> and then work my way to what type the wrapped message is and what exception lies behind the failure.

Basically I am looking for a way to intercept all failed messages (after all retries have failed) regardless of type to be able to send it to telemetry for tracking. Much just like the example of using IFailFastChecker enables you to hook into the retry mechanism before the message fails permanently.

Decorating IErrorHandler works but context is lost and by that also our original correlationId.

@mookid8000 mookid8000 transferred this issue from rebus-org/Rebus Sep 24, 2019
@mookid8000 mookid8000 added this to Assess in Rebus via automation Feb 6, 2020
Tsjunne added a commit to Tsjunne/Rebus.ServiceProvider that referenced this issue Feb 18, 2020
@Tsjunne
Copy link
Contributor

Tsjunne commented Feb 18, 2020

Made a pull request with a proposed solution

mookid8000 added a commit that referenced this issue Feb 22, 2020
@mookid8000
Copy link
Member

Fixed in Rebus.ServiceProvider 5.0.2 🙂 Thanks @Tsjunne for your contribution! 👍

Rebus automation moved this from Assess to Done Feb 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Rebus
  
Done
Development

No branches or pull requests

3 participants