This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2024-04-26
Channels
- # aleph (6)
- # announcements (1)
- # babashka (18)
- # beginners (13)
- # calva (18)
- # cider (5)
- # clojure (144)
- # clojure-europe (34)
- # clojure-nl (1)
- # clojure-norway (29)
- # clojure-uk (4)
- # emacs (9)
- # etaoin (51)
- # events (1)
- # gratitude (1)
- # hyperfiddle (9)
- # lsp (4)
- # off-topic (6)
- # pathom (61)
- # rdf (1)
- # releases (3)
- # shadow-cljs (16)
- # vrac (1)
- # yada (1)
- # yamlscript (3)
Hi, trying to consume server sent events using aleph. Any guidance? Details are in the thread.
I seem to get back and InputStream
but I really don't understand how to consume it async. I need to take action with each new event, but I can only consume the entire thing right now once the connection closes. I can't seem to find any examples of doing this.
Any snippets would be much appreciated.
Did you look at the aleph examples? They are quite good and go over multiple approaches, if I remember correctly. https://github.com/clj-commons/aleph/blob/master/examples/src/aleph/examples/http.clj
@U0AJQJCQ1 You don't really want to consume a potentially-infinite, open-ended stream like SSE with an InputStream, despite the name. A better idea is to use the byte-streams lib that aleph uses to get a manifold stream from the InputStream. (You could use raw mode, but then you're responsible for releasing netty memory yourself.)
None of the examples are for SSE, I'm afraid. You'll need to write some manifold code using the fns in manifold.stream
to split the text stream into events (split on double newlines iiuc) and then some parsing to get the data out from each event.
Could also try something like
as long as you're careful not to hold on to the head of the seq. Or to-reader
.