ring-sse
ring-sse copied to clipboard
Minimum Example ? Passing In defroutes (compojure)
Hi
I'm a bit a new to Clojure but for the life of me I can't figure out a "hello world" version of this library.
I've thus far done the following:
ANY help or example or skeleton would be much appreciated
Project Setup
$ lein new compojure rs-sse1
;;project.clj
(defproject rs-sse1 "0.1.0-SNAPSHOT"
:description "FIXME: write description"
:url "http://example.com/FIXME"
:min-lein-version "2.0.0"
:dependencies [[org.clojure/clojure "1.11.1"]
[compojure "1.6.1"]
[ring/ring-defaults "0.3.2"]
[ring-sse/ring-sse "0.2.8"]
[org.clojure/core.async "1.5.648"]
[org.clojure/data.json "2.4.0"]
]
:plugins [[lein-ring "0.12.5"]]
:ring {:handler rs-sse1.handler/app}
:profiles
{:dev {:dependencies [[javax.servlet/servlet-api "2.5"]
[ring/ring-mock "0.3.2"]]}})
Then the handler function
;;src/rs_sse1/handler.clj
(ns rs-sse1.handler
(:require [compojure.core :refer :all]
[compojure.route :as route]
[ring.middleware.defaults :refer [wrap-defaults site-defaults]]
[ring.sse :as sse]
[clojure.data.json :as json]
[clojure.core.async
:as a
:refer [>! <! >!! <!! go chan buffer close! thread
alts! alts!! take! put! timeout]]
))
(def handler
(sse/event-channel-handler
(fn [request response raise event-ch]
(a/go
(dotimes [i 20]
(let [event {:id (java.util.UUID/randomUUID)
:name "foo"
:data (json/write-str {:foo "bar"})}]
(a/>! event-ch event)
(a/<! (a/timeout 1000))))
(a/close! event-ch)))
{:on-client-disconnect #(print :info :sse/on-client-disconnect %)}))
(defroutes app-routes
(GET "/" [] "Hello Wddddorld")
(GET "/async" [] handler)
(route/not-found "Not Found"))
(def app
(wrap-defaults app-routes site-defaults))
The "/" route work (hello-world) but the /async route immediate blows up when browsing to it
clojure.lang.ArityException
Wrong number of args (1) passed to: ring.sse/event-channel-handler/fn--15418