1

so I'm always quite confused when it comes to Flux objects and everything related to them.

In my usecase I have a reactive endpoint exposed to webclient which I want to publish async elements received by spring. My code should look like the following:

    @EventListener
    @Async
    protected void handleModelChanges(ModelChangeEvent e) {
        log.debug("Event received {}", e);
        // TODO publish event on flux?
    }

    @GetMapping
    public Flux<@NonNull MyModel> modelChanges() {
        // TODO 
    }

I'm quite lost on how to implement this. I want the client to receive events once they connect in an async way. I don't want them to receive old events.

How do I do this?

2
  • @fer-marino What exactly do you want to do with @GetMapping? This is more like a server that serves a resource, as you probably know. I think you would understand better how to send events with Project Reactor by using the appropriate configuration, using the tryEmitNext method with Sinks.many() and autoCancel set to false, in publisher and subscriber mode, ApplicationEventPublisher is generally used with @EventListener. Commented Jul 26 at 17:30
  • It might be useful to have the endpoint, and when a message arrives, that endpoint executes tryEmitNext, and it is processed on the subscriber side. Commented Jul 26 at 17:45

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.