Does Vertx 3.3.3 have built in support for EventSource (SSE)?

1,622 views
Skip to first unread message

Ian Andrews

unread,
Sep 15, 2016, 10:49:32 AM9/15/16
to vert.x

I'm building a service that needs to make use of the HTML5 EventSource (Server Sent Events) API and I was wondering if there was support already built in to Vertx 3.3.3 somewhere.  I found some reference to it in an enum related to the SockJS implementation, and I also found a library for supporting it in Apex (https://github.com/aesteve/vertx-sse), but that library seemed to indicate that it would be deprecated once Vertx 3.0 came out.

Thanks,

Ian

Clement Escoffier

unread,
Sep 16, 2016, 2:29:04 AM9/16/16
to ve...@googlegroups.com
Hello,

If you use the sockJS bridge it should automatically degrade to SSE if websocket are not supported.

Clement

--
You received this message because you are subscribed to the Google Groups "vert.x" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vertx+un...@googlegroups.com.
Visit this group at https://groups.google.com/group/vertx.
To view this discussion on the web, visit https://groups.google.com/d/msgid/vertx/4dca46ec-6e0d-4207-882d-5e7fd402c733%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Konstantinos Liakos

unread,
Oct 27, 2016, 2:21:07 AM10/27/16
to vert.x
I also have the same question. The Server Sent Events logic is quite different from what the eventbus and sockJS is doing.

For SSE you want a client to connect to the server and the server to send data over the connection. The sockJS bridge requires the client to subscribe to an event(which others could also subscribe to), not just connect to an endpoint and wait for incoming data.

Arnaud Estève

unread,
Oct 27, 2016, 7:42:34 AM10/27/16
to vert.x
Hi, you can totally use the code provided in https://github.com/aesteve/vertx-sse it is usable and teste, and Vert.x 3.3.3 compliant.

I know I should contribute it to vertx-web, I'm sorry, I simply miss some time. I really hope I'll be able to submit a PR soon enough.

For now it's not Vert.x compliant because : 
- I've not written in-source documentation, only a README and a few examples
- Some methods are not codegen compliant (cross-language / polyglot issue)
- The tests are written with vertx-unit (and vertx-web currently does not depend on vertx-unit) which sounded like an issue to me, but Julien said it was not iirc

In the meantime if you really need to work with SSE without writing it yourself, you can :
- fork my repository and install it in whatever maven repo you're using
- copy paste the code in your own project

If you have time to help, that'd be even better.

Thanks a lot.

Konstantinos Liakos

unread,
Oct 27, 2016, 7:51:22 AM10/27/16
to vert.x
Actually SSE is pretty easy without any library at all.

Something like this for example works just fine:
router.route("/sse").handler(event -> {
   
event.response().setChunked(true);
   
event.response().putHeader("Content-Type", "text/event-stream");
   
event.response().putHeader("Connection", "keep-alive");
   
event.response().putHeader("Cache-Control", "no-cache");

   
vertx.setPeriodic(1000, timer -> {
     
event.response().write(String.format("data: Time is %s\n\n", LocalDateTime.now()));
   
});
});

Some built-in convenient methods however would be better.

Arnaud Estève

unread,
Oct 27, 2016, 8:03:36 AM10/27/16
to vert.x
Yes, definitely.

It's just a matter of providing (meaning : discussing) a proper built-in API.

Julien Viet

unread,
Oct 27, 2016, 10:54:30 AM10/27/16
to ve...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages