0

As per the Reactive Stream paradigm,

Currently, we’ve focused primarily on cold streams. These are static, fixed length streams which are easy to deal with. A more realistic use case for reactive might be something that happens infinitely. For example, we could have a stream of mouse movements which constantly needs to be reacted to or a twitter feed. These types of streams are called hot streams, as they are always running and can be subscribed to at any point in time, missing the start of the data.

So how can we implement this hot stream?

KayV
  • 12,987
  • 11
  • 98
  • 148

2 Answers2

2

This can be done using the ConnectableFlux as follows:

ConnectableFlux<Object> publish = Flux.create(fluxSink -> {
    while(true) {
        fluxSink.next(System.currentTimeMillis());
    }
})
  .publish();
KayV
  • 12,987
  • 11
  • 98
  • 148
  • 1
    Is there a better way in terms of scheduling? Can I create a hot stream that pulls or being pushed in every 10 seconds? – Alan Sereb Jan 24 '20 at 22:12
0

You could use MongoDB's Capped Collections to create a hot stream. By using a @Tailable on that collection it will create a publisher which publishes every new entry. With .share() it will multicast that publisher, so that not every subscription creates a new database connection.

TimoTheus
  • 11
  • 2