Dynamically attached sinks

Is it possible to create a source that will be partially consumed by many sinks, attached and detached at arbitrary moments? For example stream of numbers emitting every second, and first sink somehow attached and consume items from 100 to 400, other sink attached latter and consume 300 to 500 and so on.

Take a look at the broadcast hub and see if that fits your use case, docs: Dynamic stream handling • Akka Documentation

1 Like

Looks promising, thanks. However, each new sink receives the entire stream from the beginning, even if it connected when other sinks had already consumed half of the elements. Even though I set the minimum buffer size.

Then I suspect you are doing something wrong. Make sure you only materialize the stream with the hub once, and then only the materialized source for each dynamic sink.

If you want elements to “run by” when there are no subscribers attached rather than backpressure you can achieve that by attaching an always present ignore sink.

1 Like

Yes, my bad! I repeatedly materialized the hub, not the source it returned.Thanks a lot!