Scala: Receiving Server-Sent-Events

http, playframework-2.0, scala, server-sent-events, spray

Solution

You have several possibilities:

In Play 2.3, the WS library is now a separate library, so that should help. RC2 is already available

Alternatively, you could depend on Play 2.x and use a `StaticApplication` like so:

val application = new StaticApplication(new java.io.File("."))

This will essentially bootstrap a Play application, and from there on you can use the `WS` library as usual

Problem

Set-up: A project I am working on has a pub/sub server with an HTTP interface. Subscription works by accepting server-sent-events. ``` curl -X GET server:port/topics/news ``` which will be pushed whenever a message is published to the given topic URL ``` curl -X PUT server:port/topics/news -d "Politician Lies!" ``` Problem: I have a scala project which needs to subscribe to this pub/sub server. The Play! framework is able to handle this by using PlayWS with Enumeratee + Iteratee. Unfortunately, the PlayWS library requires that a Play! Application is in scope and I am not using Play. Is there a library (with minimal dependancies) I can use which allows me to accept server-sent-events? I'll need at least one working example in order to get started. I have a preference for scala libraries but I'm willing to accept a Java solution if I have to.

Original source