Recently I started working with reactive streams and event based systems using projectreactor.io. I thought it would be nice to use an event based approach to communicate between UI and server, so I dug around a bit and found vaadin-spring and vaadin-push.
So here is my buzzword-clock, a single file application that shows the current time using as many fancy technologies as possible:
- Spring Boot with web-starter
- Spring @Scheduled for the ticking clock
- vaadin spring for the UI
- vaadin push with atmosphere for updating the web-UI from the server
- Reactor for the (async) EventBus.
For a full pom.xml, check out the repo.
Main Building blocks
- It is a spring-boot application, starting an embedded tomcat servlet container.
- It defines a Vaadin UI spring bean that is discovered and bound to “/”
- The “clock” bean is scheduled, its method is triggered every second.
- Using the reactor framework, it defines an Environment and an EventBus bean that loosly couples the server and the UI.
- Every second an event is fired (notify) containing the current local time as payload
- The UI consumes the localtime event and updates the label with the formatted time
Thanks to
For the push part, I leveraged the Using Server-Push in a Vaadin app example by P.J.Meisch.
Open points
Seams like I didn’t get the @EnableReactor annotation … I had to configure the reactor environment in a static block.