server-sent-eventsjava-http-client

SSE Java 11+ client example (w/o dependencies)


I'm looking for examples using a plain JDK11+ http client reading server sent events, without extra dependencies. I can't find anything about sse in the documentation either.

Any hints?


Solution

  • Java 11 based implementation of SSE (Server-sent Events) client here:
    SSE Client

    It provides a pretty simple usage of processing of SSE messages.

    Example usage:

    EventHandler eventHandler = eventText -> { process(eventText); };
            SSEClient sseClient = 
    SSEClient sseClient = SSEClient.builder().url(url).eventHandler(eventHandler)
        .build();
    sseClient.start();
    

    Note: I am the author of this SSE client.