Docs

Documentation versions (currently viewingVaadin 24)

Reactive Browser Callable Services Hilla

How to create reactive browser callable services for a Vaadin Hilla user interface.

When building a user interface with Vaadin Hilla, you would use reactive browser callable services to push messages from the server to the browser. A reactive service is a service that returns a Flux from Reactor.

Here is an example of a browser callable service that emits the current date and time every second:

@BrowserCallable
public class TimeService {

    @AnonymousAllowed
    public Flux<@Nonnull String> getClock() {
        return Flux.interval(Duration.ofSeconds(1)) 1
                .onBackpressureDrop() 2
                .map(_interval -> Instant.now().toString()); 3
    }
}
  1. Emit a new message every second.

  2. Drop any messages that for some reason can’t be sent to the client in time.

  3. Output the current date and time as a string.

Hilla generates the necessary TypeScript types to subscribe to this service from the browser.

For more information about updating the UI using a reactive service, see the Reactive Streams documentation page.