Here is a solution for SSE over http-kit channels
(defn server-event-source [ch] ;; Adding a mult here is dangerous because
it bleeds the underlying ;; channel dry. We should provide the mult via
modular.async (let [m (async/mult ch)] (fn [req] (let [ch (async/chan 16)]
(async/tap m ch) (with-channel req net-ch (on-close net-ch (fn [_]
(async/untap m ch) (async/close! ch))) (send! net-ch {:headers headers}
false) (go-loop [] (when-let [data (<! ch)] (println "Got data! " data)
(send! net-ch (->message data) false) (recur))))))))
https://github.com/juxt/modular/blob/master/modules/http-kit-events/src/modular/http_kit/events.clj
On Saturday, 6 December 2014 17:03:41 UTC, Lars Ole Avery Simonsen wrote:
>
> Hi guys
>
> I am trying to implement Server Sent Event support in a small hobby
> project based on the http-kit server framework and compojure.
>
> I am still quite new to clojure in general, so it may very well be that I
> am missing something obvious, but this SSE detail has me stumped.
>
> What I have tried is to take inspiration from the Eventual
> <https://github.com/ninjudd/eventual> library for the SSE implementation
> (which is aimed at jetty). I have changed the Eventual implementation so
> that it uses the http-kit async-channel implementation for data
> transmission. What I am seeing is that everything seems to run without
> errors except for the fact that no data is being received at the
> EventSource in the browser.
>
> If I allow the sse channel to close immediately after opening (which is
> pretty useless), the initial message is received at the browser side, but
> if I keep the connection open, nothing gets received.
>
> Having had a look at the http-kit internals, my suspicion is that the
> socket doesn't get flushed and so all my attempts at communication are
> sitting in some buffer somewhere.
>
> All SSE implementations I have looked at for other platforms have explicit
> calls to flush the socket buffers on the long lived connection after each
> message transmission.
>
> Does anyone have any suggestions as to a better way to achieve SSE support
> in a http-kit based server? Or maybe ideas as to what I might be doing
> wrong?
>
> Thanks in advance.
>
> LOAS
>
>
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
---
You received this message because you are subscribed to the Google Groups
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.