Receiving Server Sent Events (SSE) with JAX-RS 2.1 and Java EE 8

To receive Server Sent Events (SSE) with a Java JAX-RS 2.1 (Java EE 8) client you will need an additional dependency:


For the initialization of a SseEventSource you need a WebTarget which comes from a "stock" JAX-RS client:

import static java.util.concurrent.TimeUnit.SECONDS;

public class SSEClientIT {

    private Client client;
    private WebTarget tut;

    public void initClient() {
        this.client = ClientBuilder.newClient();
        this.tut ="http://localhost:8080/sse/resources/beats");
...with the target you can create a SseEventSource to register an instance of: Consumer<InboundSseEvent> as listener:

    public void init() throws IOException {
        SseEventSource sse = SseEventSource.
                .reconnectingEvery(2, SECONDS)
        //block here, otherwise the test method will complete

    void onMessage(InboundSseEvent event) {
        String id = event.getId();
        String name = event.getName();
        String payload = event.readData();
        String comment = event.getComment();

See you at Java EE 8 on Java 9, at Munich Airport, Terminal 2

NEW: Online Workhop Effective WebApps without Frameworks is also coming to: MUC Airport.

Airport MUC workshops: Web (SPA, PWAs, Offline, Desktop, Mobile) Applications Essentials and Effective Web Applications. No migrations. #usetheplatform

Podcast: and newsletter:

A book about rethinking Java EE Patterns


Post a Comment:
  • HTML Syntax: NOT allowed
Online Workshops
...the last 150 posts
...the last 10 comments