A demo app to push data from database to browser in realtime with reactivemongo and server side events
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
app
conf
project
public
README.md
build.sbt

README.md

A Play Framework demo app to push data from database to browser in realtime with reactivemongo and server sent events (or WebSockets)

This controller method pushes new data from mongo in live to a SSE socket :

 def search(filter: String) = Action { 
    val query = QueryBuilder().query(BSONDocument("message" -> BSONRegex(filter, "")))

    //query results asynchronous cursor
    val cursor = collection.find[JsValue](query, QueryOpts().tailable.awaitData)

    //create the enumerator
    val dataProducer = cursor.enumerate

    //stream the results
    Ok.chunked(dataProducer through EventSource()).as("text/event-stream")
}

Then the client is able to display new entries as soon as they are inserted in database (no pull needed from browser)

This application contains some JSON serialization and client side HTML5 validation samples too