0

I was researching the Java Flux API when I noticed from some tutorials that you can only subscribe to one publisher. Yet, I see a use-case where having multiple publishers to a single subscribe is useful: some sort of a data/message bus.

The only solution I found is encapsulating an array of subscribers and 1 publisher inside the bus.

My question is, which is the correct approach from a reactive point of view to this problem?


I'm interested in solving this by implementing my own Publishers/Subscribers etc. (using the Java 9 java.util.concurrent.Flow API) This project is for learning purpouses, not for production.

Brian Clozel
  • 56,583
  • 15
  • 167
  • 176
taigi100
  • 2,609
  • 4
  • 23
  • 42
  • It seems like you want to combine streams. There are plenty of operators allowing you to do this. – a better oliver Sep 08 '18 at 19:57
  • @abetteroliver I want to combine multiple publishers into one. What operators allow you to do this specifically? using the `java.util.concurrent.Flow` interfaces. Thanks! – Ariel Mirra May 30 '21 at 04:20

1 Answers1

0

You can use Spring Reactor, an implementation of Java Publishers API. It has operators like concat(), merge() etc. to combine the Streams for a given Subscriber. https://projectreactor.io/docs/core/release/api/

Vikram Rawat
  • 1,472
  • 11
  • 16