This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-05-03
Channels
- # boot-dev (1)
- # cider (27)
- # cljsjs (6)
- # cljsrn (11)
- # clojure (249)
- # clojure-dusseldorf (1)
- # clojure-finland (1)
- # clojure-greece (1)
- # clojure-italy (28)
- # clojure-nl (12)
- # clojure-russia (2)
- # clojure-spec (5)
- # clojure-uk (27)
- # clojurescript (24)
- # clojutre (2)
- # component (8)
- # cryogen (1)
- # cursive (7)
- # datomic (61)
- # editors (18)
- # emacs (1)
- # events (1)
- # figwheel (4)
- # fulcro (35)
- # graphql (4)
- # jobs (3)
- # jobs-rus (1)
- # keechma (1)
- # leiningen (1)
- # london-clojurians (1)
- # luminus (62)
- # off-topic (154)
- # onyx (23)
- # pedestal (43)
- # portkey (66)
- # re-frame (49)
- # reagent (23)
- # shadow-cljs (92)
- # tools-deps (113)
- # uncomplicate (2)
I'm very interest in pedestal, I want to write a web server with core.async. is there any examples for pedestal with core.async? also, i'm curious about how to deal with jdbc with core.async.
Hi @doglooksgood, I’m glad to hear about your interest in Pedestal! I recommend reading through the Pedestal documentation, in particular the section on interceptor return values (http://pedestal.io/reference/interceptors#_interceptor_return_values). Unfortunately, I don’t have a sample project to point you to but I just created an issue (https://github.com/pedestal/pedestal-docs/issues/104) to track getting that done.
In a nutshell, Pedestal interceptors support going async. You just need to return a core.async channel which will yield an updated context
that's great, if I understand correct, pedestal can use core.async channel as a response. so basically i can use a go
in handler and do everything I want?
If you have a handler function, it can’t return a channel. But an interceptor can return a channel which will return a context map at some point
http://pedestal.io/reference/streaming#_using_a_core_async_channel_as_the_response this part looks confusing
Hm, I need to look into that because the following does not work
(defn home-page
[request]
(async/go
(ring-resp/response "Hello World!")))
while this does
(def home-page
(i/interceptor
{:name ::home-page
:enter (fn [ctx]
(async/go
(assoc ctx :response (ring-resp/response "Hello World!"))))}))
@doglooksgood I’m mistaken, when working with servlets you can return a channel as the response body
So this works
(defn home-page
[request]
(-> (async/go "Hello World!")
ring-resp/response
(ring-resp/content-type "text/html")))
You don’t need to deploy your app as a war. You can start up a container to run it. Jetty is the popular choice and the default
(defn index [request]
{:status 200
:body (go "hello")})
(def routes
(route/expand-routes
#{["/index" :get index :route-name :index]}))
(def service-map
(-> {::http/routes routes
::http/type :immutant
::http/port 8890}
http/default-interceptors
http/dev-interceptors
http/create-server))
(mount/defstate server
:start
(http/start service-map)
:stop
(http/stop server))
(comment
(mount/start #'server))
I just tried with this, but it failed.
the error is
Caused by: java.lang.IllegalArgumentException: No implementation of method: :default-content-type of protocol: #'io.pedestal.http.impl.servlet-interceptor/WriteableBody found for class: clojure.core.async.impl.channels.ManyToManyChannel
That’s strange. I expect immutant to use the same servlet code as jetty in this case
async handler: https://gist.github.com/ddeaguiar/9172555a94d75c749e4a059af6942918#file-gistfile1-txt-L15-L19