1

For some time have been using create an EmitterProcessor with built in sink as follows:

EmitterProcessor<String> emitter = EmitterProcessor.create();
FluxSink<String> sink = emitter.sink(FluxSink.OverflowStrategy.LATEST);

The sink publishes using a Flux .from command

Flux<String> out = Flux
        .from(emitter
        .log(log.getName()));

and the sink can be passed around, and populated with strings, simply using the next instruction.

Now we see that EmitterProcessor is deprecated.

enter image description here

It's all replaced with Sinks.many() like this

Many<String> sink = Sinks.many().unicast().onBackpressureBuffer();

but how to use that to publish from?

rupweb
  • 3,052
  • 1
  • 30
  • 57

1 Answers1

0

The answer was casting the Sinks.many() to asFlux()

Flux<String> out = Flux
        .from(sink.asFlux()
        .log(log.getName()));

Also using that for cancel and termination of the flux

sink.asFlux().doOnCancel(() -> {
    cancelSink(id, request);
});
    
/* Handle errors, eviction, expiration */
sink.asFlux().doOnTerminate(() -> {
    disposeSink(id);
});   

UPDATE The cancel and terminate don't appear to work per this question

rupweb
  • 3,052
  • 1
  • 30
  • 57