In Reactor 3, what's the most efficient way to split a heterogeneous flux to multiple fluxes by pattern matching? (And subsequent operations on each flux may be very different)
For example,
Source Flux: a->b->c->a->b->c
||
vv
A Flux: a->a->a
B Flux: b->b->b
C Flux: c->c->c
I'm new to reactive programming, and the only solution I come up with is share()
+filter()
, like
val shared = flux.share();
shared.filter(x -> x.tag=='a').subscribe(a -> consumeA(a));
shared.filter(x -> x.tag=='b').subscribe(b -> consumeB(b));
shared.filter(x -> x.tag=='c').subscribe(c -> consumeC(c));
Is this the best solution, or is there any better paradigm for this problem?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…