How eventBus works in MVP and Spring boot?

1.7k Views Asked by At

can someone explain me how the eventbus works, I saw all doc about that but I didn't understand

I will give you what I want to do; So I have AccountPresenter and AccountView so in my view I have Button to open window in which I create my account, what I want to do is to slipe the view and creation of the window in an other View Presenter and can it in AcccountPresenter using eventBus of spring vaadin or an otther EventBus. I don't really understand the role of this .

Thank you

2

There are 2 best solutions below

0
KLHauser On

For event-handling in spring you first should create an event like:

public static class CloseOpenWindowsEvent extends ApplicationEvent {
    private static final long serialVersionUID = -4672026509699779702L;

    public CloseOpenWindowsEvent(Object source) {
        super(source);
        // TODO Auto-generated constructor stub
    }
}

Then you would need something to publish your event:

@Autowired
private ApplicationEventPublisher eventPublisher;
...
eventPublisher.publishEvent(new CloseOpenWindowsEvent(MyUI.getCurrent()));

and somebody who listens to it:

@EventListener
public void closeOpenWindows(final CloseOpenWindowsEvent event) {
    for (Window window : getWindows()) {
        window.close();
    }
}

But as smooth as this is, in your case it's not the way to go I think. Instead you should use Vaadin's Navigator and adjust the ClickListener of your button to navigate to the other view.

UI.getCurrent().getNavigator().navigateTo(otherView.getViewName());

Checkout https://github.com/khauser/microservices4vaadin/tree/master/microservices/frontend, there you would have both in place. The event-handling with spring and using the Navigator.

0
naib khan On

In Spring EventBus actually follow the Reactor pattern. Reactor pattern is to be used only when a user doesn’t expect a response directly from the application as we only execute background jobs using this Reactor demonstration.
By using EventBus, heap memory is assigned to the application and they executes tasks in parallel. However Reactor design pattern can process over 15,000,000 events per second with the fastest non-blocking Dispatcher.

For details please check the link Spring Reactor Tutorial