But I receive both events with both consumers.
Right. Because you send both events to the same reactor
just to defaultKey
.
And subscribe both consumers
to the defaultSelector
.
In this case it doesn't have value which types of Event
you use: they all will be dispatched by default Selector
strategy.
I think you need to use ClassSelector
:
reactor.notify(a);
reactor.notify(b);
reactor.on(Selectors.T(A.class), new Consumer<Event<A>>() {});
reactor.on(Selectors.T(B.class), new Consumer<Event<B>>() {});
Of course, you have to type Selectors.T
for each class-consumer
, but it is more simpler then ObjectSelector
and custom Event
.
UPDATE
How to inject a custom consumer filter
:
Reactors.reactor()
.eventFilter(new GenericResolverFilter())
.get()
And it's up to you how to resolve a generic argument from consumerKey
Object and each Consumer
from List<T> items
. Anyway you should think here about some caching to allow to Reactor continue to be reactive
.