Fork me on GitHub
#clojure
<
2022-08-20
>
wombawomba14:08:03

I'm looking for a RPC lib for a Clojure server and client that's quick to get started with, and allows me to stream data without buffering it into memory. Any suggestions?A

jumar14:08:14

You could say HTTP rest api is an RPC too. But what exactly do you mean by without buffering it into memory? You mean without loading all the data into memory at once?

👍 1
wombawomba15:08:48

I mean, I suppose HTTP works, but I was ideally looking for something a little less hands-on (with HTTP I'd have to set up a whole API; really I just want a hassle-free but performant way to call a bunch of functions)

wombawomba15:08:35

ideally I'd like to be able to have bidirectional communication as well, which would require something like long polling with a REST API

wombawomba15:08:30

I'd probably go with gRPC, but it seems like that would require me to maintain a bunch of boilerplate

amithgeorge15:08:39

I haven't used it, remember reading about it somewhere- https://github.com/sunng87/slacker

respatialized15:08:51

If it's a trusted execution context you could just wrap some streaming around the capabilities of the core.server namespace, which seems much lighter weight than gRPC or HTTP https://clojuredocs.org/clojure.core.server/start-server

1
respatialized15:08:40

Send the function you want to eval (as data), get a streaming result back

respatialized15:08:51

https://clojuredocs.org/clojure.java.io/input-stream The core.server instance is intended to operate over a socket connection, so you could potentially turn that connection into an InputStream

wombawomba17:08:21

@U0A5B1LJU Slacker looks really cool, but AFAICT you can't really stream data with it

wombawomba17:08:45

@UFTRLDZEW cool, I'll take a look at that; thanks

chepprey22:08:04

@U15RYEQPJ for something simple and minimal, I've had success sending EDN (or Transit) over a websocket. I did have the luxury of having a clojure backend and clojurescript front end, but you can just as easily send JSON messages too, or anything really, the "socket" is agnostic about the content of the messages. It's bi-directional message passing. If you need request/response semantics, you'll need an additional layer to manage that. Streaming is also supported but I've never done it in clojure.

wombawomba09:08:01

@UHL84CDTP good idea. With websockets, what I'd worry about is that it's hard to guarantee at-least-once delivery. You'd need to manually add a mechanism to track if messages are getting through or not

pithyless11:08:15

In case you're not familiar with https://github.com/ptaoussanis/sente - just throwing it out there. Not sure if it would work well with arbitrary streaming data, but perhaps if you can chunk/batch it correctly? At the very least, it gives you an idea on dealing with websocket reconnects, syn/ack delivery, etc.

Ted Ciafardini21:08:20

I am trying to deploy a luminus-generated web application to heroku. It’s a small full-stack application that queries a psql table for some blog_posts and then renders some reagent components based on that data. It works fine locally. At this point I have been able to run migrations successfully to set up tables & populate them with data. I can see my tables & data in the DB when I connect to the heroku psql “resource” with my heroku credentials. The app itself builds without errors & I can see the app running when I click “Open App” within heroku - but it looks like it isn’t getting any data from the database to render. I believe the issue is that it isn’t using the proper database-url which I have tried setting in prod-config.edn in the parent directory:

{:prod true
 :port 5432 
 :database-url (System/getenv "DATABASE_URL")}
I also tried “ensuring” that this config was used in my Procfile like so:
web: java -Dclojure.main.report=stderr -Dconf=prod-config.edn -cp target/uberjar/clj-blog.jar clojure.main -m clj-blog.core
Still no luck. Not really sure where to go from here or how to debug this within Heroku. This is my first time trying to deploy something. Any help would be greatly appreciated 🙂

hiredman22:08:31

Is prod-config.edn in your uberjar?

Ted Ciafardini22:08:56

from project.clj:

:profiles
  {:uberjar {:omit-source true
             :aot :all
             :jvm-opts ["-Dconf=prod-config.edn"]
             :uberjar-name "clj-blog.jar"
             ;source paths and resource paths are very lightweight & specific
             ;prod/clj does not include support for starting and stopping the server within REPL for example
             :source-paths ["env/prod/clj" "env/prod/cljc" "env/prod/cljs"]
             :resource-paths ["env/prod/resources"]
             :prep-tasks ["compile" ["run" "-m" "shadow.cljs.devtools.cli" "release" "app"]]}

hiredman22:08:01

If you open your uberjar, is the prod-config.edn file in it?

Ted Ciafardini22:08:54

I don’t see it.

hiredman22:08:59

I don't know what library you are using for reading configs, but there is a very good chance it loads configs as resources from a classloader, the most common way to make things available like is in jarfiles or directories on the classpath

hiredman22:08:56

The only thing on your classpath is your uberjar, so if the config file is not in there, there is a good chance whatever you are using to load it can't find it

Ted Ciafardini22:08:05

I think luminus uses something called cprop

Ted Ciafardini22:08:12

I added a log & it looks like it’s grabbing the url correctly which is weird:

(defstate ^:dynamic *db*
  :start (if-let [jdbc-url (env :database-url)]
           (do
             (log/warn (str "database url is the following I guess:" (env :database-url)))
             (conman/connect! {:jdbc-url jdbc-url}))
           (do
             (log/warn "database connection URL was not found, please set :database-url in your config, e.g: dev-config.edn")
             *db*))
  :stop (conman/disconnect! *db*))
The log gives the correct psql url

wevrem23:08:02

Have you asked on the #luminus channel also?

Edward Ciafardini01:08:30

Will do, thank you

Ted Ciafardini03:08:32

It’s working now - thanks everybody gratitude