Skip to content

Instantly share code, notes, and snippets.

@mrmcc3
Last active July 21, 2017 14:48
Show Gist options
  • Save mrmcc3/b3cae01af7a0f1d508341e3e0aac1db9 to your computer and use it in GitHub Desktop.
Save mrmcc3/b3cae01af7a0f1d508341e3e0aac1db9 to your computer and use it in GitHub Desktop.
Clojure EventSource client via java interop with Jersey SSE impl. (example uses firebase streaming api)
(defproject sse-example "0.1.0-SNAPSHOT"
:dependencies [[org.clojure/clojure "1.8.0"]
[cheshire "5.5.0"]
[org.glassfish.jersey.media/jersey-media-sse "2.22.2"]])
(ns sse
(:require [cheshire.core :as json])
(:import [javax.ws.rs.client ClientBuilder]
[org.glassfish.jersey.media.sse EventSource EventListener SseFeature]))
(let [es (-> (ClientBuilder/newBuilder) (.register SseFeature) .build
(.target "https://your-firebase-name.firebaseio.com.json")
(.queryParam "auth" (into-array Object ["jwt/secret"]))
EventSource/target .build)
el (reify EventListener
(onEvent [_ e]
(println (.getName e) (json/decode (.readData e)))))]
(.register es el)
(.open es))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment