Last active
July 21, 2017 14:48
-
-
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)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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"]]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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