JAX-RS 2.1 SSE Client API example using Glassfish 5 on Docker

Along with the Server API for SSE, JAX-RS 2.1 (part of Java EE 8) also has an equivalent client side API

Here is a quick peek – you can grab the project from Github

To summarize

  • we use a @Singleton EJB with @Startup
  • during initialization
    • create a single action (one time) Timer  i.e. @PostConstruct
    • and instantiate the SSEEventSource – its a public SSE source
  • when the timer expires, the @Timeout annotated method gets triggered
    • opens the SSE connection
    • prints them out – this action is registered as a callback (written as a Java 8 lamda in this case)
  • Execution thread pool(s) – notice this in the logs
    • the timer itself is triggered in the EJB thread pool
    • SSE event callbacks are executed in the ManagedExecutorService thread pool (thanks to Java EE Concurrency Utilities)

sse-client-output.jpg

To run using Docker

Refer README

Further reading

Cheers!

Advertisements

About Abhishek

Loves Java EE, distributed KV stores and messaging systems. Frequently blogs at abhirockzz.wordpress.com as well as simplydistributed.wordpress.com. Oh, I have also authored a few (mini) books, articles, Refcards etc. :-)
This entry was posted in Java EE and tagged , , , , , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s