clojure

New to Clojure? Try the #beginners channel. Official docs: https://clojure.org/ Searchable message archives: https://clojurians-log.clojureverse.org/
murtaza52 2020-12-28T08:32:37.019900Z

@timofey.sitnikov there is a fulcro channel, have you tried asking there ?

1
GGfpc 2020-12-28T13:12:27.023Z

Has anyone here used Langhor for RabbitMQ? If so, how can I have multiple threads consuming in parallel? I have tried the :executor option with a fixed thread pool but that results in connection refused for all but one consumer. Supposedly you can just create multiple consumers and they are executed in a threadpool by default, but my messages seem to be processed in a single thread. ๐Ÿ˜•

(defn init
  [f]
  (if (false? @started)
    (let [conn (rabbit/connect {:uri      (System/getenv "RABBITMQ_URL")})
          chnl (channel/open conn)
          queue-name "goodstats.queue"]
      (timbre/info "Starting AMQP subscriber at: " (System/getenv "RABBITMQ_URL"))
      (queue/declare chnl queue-name {:exclusive false :auto-delete false})
      (consumers/subscribe chnl queue-name f {:auto-ack false})
      (consumers/subscribe chnl queue-name f {:auto-ack false})
      (consumers/subscribe chnl queue-name f {:auto-ack false})
      (consumers/subscribe chnl queue-name f {:auto-ack false})
      (reset! started true))))

emilaasa 2020-12-28T13:19:39.023200Z

Do you want each consumer in a different thread?

GGfpc 2020-12-28T13:21:15.023600Z

They can share a thread pool. Really what I want is for each consumer to be able to process one message at a time, but N consumer to process N threads at once

emilaasa 2020-12-28T13:30:27.023800Z

When using Java I've used one channel per thread, I think I read it in the java api docs.

emilaasa 2020-12-28T13:31:11.024Z

I saw that you could provide something like a threadfactory to langhor which might do something, but I wouldn't count on it handling concurrency (well) by itself

lukasz 2020-12-28T15:03:15.024400Z

Apologies for a shameless plug - but it's coming from a good place ๐Ÿ˜‰ My team's RabbitMQ client comes with multi-threading (and adjustable prefetch) support out of the box - and it's based on the Java client directly, rather than use Langhor (which we started with years ago). One caveat is that it has a hard-ish dependency on Component, but you can use it without it with relatively small effort: https://github.com/nomnom-insights/nomnom.bunnicula

Norman Ziebal 2020-12-28T15:37:46.026100Z

Would you prefer Clojure or ClojureScript for FaaS? Personally I am concerned about the start up times for JVM.

valtteri 2020-12-28T16:00:00.026200Z

Depends on use-case. If youโ€™re expecting fast response to infrequent HTTP-requests then Iโ€™d probably pick CLJS. However I think the startup time is one of the smallest problems to solve when entering FaaS territory. ๐Ÿ™‚

valtteri 2020-12-28T16:02:16.026400Z

If youโ€™re worried, you can write most of your code in cljc and easily swap between runtimes. ๐Ÿ™‚

โž• 1
vemv 2020-12-28T16:12:11.026700Z

this new feature might change things a little https://aws.amazon.com/blogs/aws/new-provisioned-concurrency-for-lambda-functions/

souenzzo 2020-12-28T17:43:51.029100Z

About cognitect.anomalies: (not sure if it's the right channel) There is a field :cognitect.anomalies/message When I'm using anomalies in a ex-info, should I use the same value for ex-info msg and for :cognitect.anomalies/message? Something like (let [msg ...] (throw (ex-info msg {:cognitect.anomalies/message msg ....}))) ? Or they have different meanings? EDIT: I just see that :cognitect.anomalies/message is :opt, so may I skip it in ex-info?

ghadi 2020-12-28T17:44:47.029900Z

I use anomalies as an alternative to exceptions

souenzzo 2020-12-29T13:28:42.054100Z

result, _ := op();

dominicm 2020-12-30T09:11:43.085600Z

Fwiw, datomic api uses anomalies and can be used for inspiration

souenzzo 2020-12-30T12:31:06.096800Z

I know, i catch some exceptions from there and I can dig into it. But as a non-oss, is harder to see

souenzzo 2020-12-28T17:47:04.030300Z

Do you return it? So, you don't use "let it crash"?

souenzzo 2020-12-28T17:53:03.031100Z

There is any good oss example of usage?

Norman Ziebal 2020-12-28T17:58:17.032700Z

@valtteri could you elaborate on the other problems when using clojure with FaaS, I would be curious to know.

ghadi 2020-12-28T18:02:52.033900Z

I make my functions return data->data. The caller still needs to check for success

ghadi 2020-12-28T18:03:02.034400Z

Or let it crash if necessary

ghadi 2020-12-28T18:03:48.034900Z

Or whatever policy you want

souenzzo 2020-12-28T18:08:15.035100Z

right. so caller may write it own msg to ex-info with a possibly generic error, and :cognitect.anomalies/message will came from "the cause"

ghadi 2020-12-28T18:08:51.035600Z

Whatโ€™s your goal?

valtteri 2020-12-28T19:24:04.036300Z

@norman.ziebal oh, I didnโ€™t mean that Clojure would be a problem with FaaS. Actually I think the language itself is a great fit for FaaS. What I wanted to say is that in my experience people are too worried about startup penalty, which I perceive as a minor (technical) thing that can be worked around. I think there are more fundamental problems to be worried about, such as splitting the problem domain into distinct deployable artefacts and managing dependencies between them.

๐Ÿ‘ 2
emilaasa 2020-12-28T20:21:23.036900Z

Good on you for open-sourcing it! Looks good docs wise too. I'll give it a shot! ๐Ÿ˜ƒ

emilaasa 2020-12-28T20:23:40.037100Z

My org quite recently moved towards using rabbitmq to "just do pub-sub" but it seems amqp + rabbit has quite a bit of complexity to handle, so having libraries with opinions is great.

p-himik 2020-12-28T21:23:57.037300Z

@ghadi "The caller needs to check for success" sounds a lot like C return codes. I haven't really dealt with such an approach in Clojure. Does it not get overwhelming, to have to check the result in every single function that can get an "anomaly" from one of its callees?

๐Ÿ‘€ 1
lukasz 2020-12-28T21:28:08.037500Z

Yeah, the amount of configuration options is quite overwhelming on the client and server side. We have basically set everything to be as safe as possible, while trading off throughput a bit (although we push 10s (or 100s now) of thousands of messages every hour and it's been fine. One thing to watch out for - there's v3 coming which will not be backwards compatible

frodeaux 2020-12-28T23:17:15.040500Z

Does anybody have a recommendation or pointers for a tutorial/into on cljfx? I've got the basic example at https://github.com/cljfx/cljfx running, but I'm not sure how to move past this. I'm relatively new with only moderate Clojure + Leiningen experience.

phronmophobic 2020-12-28T23:18:03.040700Z

you can try the #cljfx channel. they're pretty helpful there.

frodeaux 2020-12-28T23:18:38.040900Z

Thx