clj-commons / manifold

A compatibility layer for event-driven abstractions
1.02k stars 108 forks source link

Question: Possibility to back-propagate errors #44

Closed rkoch closed 9 years ago

rkoch commented 9 years ago

I am using the manifold.bus to communicate between components in my service.

The flow is usually like this:

event on api component ----->  (1) store event in database
                         |---> (2) some coercions ---> send event to an external service
                         |---> (3) some other invocation when intercepting this message

The problem is, that in the api component, I don't know whether any of these consumers throw an exception. For the first two listeners it is crucial that the user knows if anything went wrong with his initial event. The easiest approach would be to make the API handler aware of the components handling (1) and (2) and process it sequentially. But I did like the approach of a central "nerve system" which totally decouples components and would mean adding new listeners without changing the dependency graph.

Could you give me a hint how this issue could be tackled the right "async/manifold" way? Thanks!

ztellman commented 9 years ago

The idea of the bus is that once it goes downstream, the publisher doesn't care anymore. I think having a central handler that explicitly routes it to the various handlers is the best idea, but you don't necessarily have to handle them sequentially, you can wrap them each in a future and zip everything together (though that will short-circuit if any of the tasks fail).

I'm going to close the issue, but feel free to reopen if you have further questions.

rkoch commented 9 years ago

Thank you for the clarification!

I created a central component, which routes the request to the registered downstream-handlers and returns thrown errors to the caller.