1

The manual describes well how to consume simple messages using java.util.function.Consumer<T> and make a through processing in a single processor method with java.util.function.Function<T, T>, but it isn't clear the way to produce a message triggered by producer service itself. For instance, produce the message containing the value received by RestController.

EDIT

There is a solution, but it relies on a deprecated reactor.core.publisher.EmitterProcessor

public class MyProcessingService {

    private final EmitterProcessor<Message<MyTask>> processor = EmitterProcessor.create(); // <- DEPRECATED

    @Bean
    public Consumer<Message<MyResult>> myResult() {
        return input -> {
            log.info("Received: {}", input);
        };
    }

    @Bean
    public Supplier<Flux<Message<MyTask>>> myTask() {
        return () -> processor;
    }

    public void sendMyTask(String payload) {
        processor.onNext(MessageBuilder.withPayload(MyTask.builder().payload(payload).build()).build());
    }
    
}

Is there any recommended solution here? Thanks in advance.

meridbt
  • 304
  • 1
  • 11

0 Answers0