Clojure Queues with RabbitMQ

Поділитися
Вставка
  • Опубліковано 12 січ 2025

КОМЕНТАРІ • 12

  • @TomasBrejla
    @TomasBrejla 3 роки тому +4

    Regarding closing channel/connection...
    Using `with-open` macro might be a way better option than manually closing the channel and connection.
    `with-open` has a `let`-like form and automatically surrounds the expression in itself with a try-finally block, in which it pefrorms the closing for you. The object to be closed doesn't have to implement `java.io.Closable`, it just needs to have a .close() method on itself. Therefore it can be used for both `rmq/connect` connection (which is Closable) and for `lch/open` channel (it isn't Closable, but has .close() method).
    Here's an example:
    ```
    (with-open [conn (rmq/connect)
    ch (lch/open conn)]
    (println "connection and channel open for 5 secs")
    (Thread/sleep 5000)
    (println "connection and channel will be closed even after exception")
    (throw (ex-info "boom!" {})))
    ```
    And here is what it macroexpands to:
    ```
    (clojure.walk/macroexpand-all
    '(with-open [conn (rmq/connect)
    ch (lch/open conn)]
    (println "connection and channel open for 5 secs")
    (Thread/sleep 5000)
    (println "connection and channel will be closed even after exception")
    (throw (ex-info "boom!" {}))))
    ;; => (let*
    ;; [conn (rmq/connect)]
    ;; (try
    ;; (let*
    ;; [ch (lch/open conn)]
    ;; (try
    ;; (do
    ;; (println "connection and channel open for 5 secs")
    ;; (. Thread sleep 5000)
    ;; (println "connection and channel will be closed even after exception")
    ;; (throw (ex-info "boom!" {})))
    ;; (finally (. ch clojure.core/close))))
    ;; (finally (. conn clojure.core/close))))
    ```

    • @eugenej.5584
      @eugenej.5584 3 роки тому +2

      Yeah with-open is a good example how Lisp syntax allows to allocate variables and resources in a scope with auto collect/release.

    • @onthecodeagain
      @onthecodeagain  3 роки тому +1

      Yeah thats much nicer :) thanks!!

  • @SebastianAnklamm
    @SebastianAnklamm 3 роки тому +1

    I am always amazed how much well digestible content you are able to pack into 15 minutes. Top notch as always.

  • @ScottRehorn
    @ScottRehorn 3 роки тому +1

    Excellent stuff! Nice pacing and well-thought out presentation - keep up the good work. ps I hope you hit your 1k subs! You are soooo close :)

  • @eugenej.5584
    @eugenej.5584 3 роки тому +3

    Kafka next? :D

    • @onthecodeagain
      @onthecodeagain  3 роки тому +1

      Mayybee??

    • @eugenej.5584
      @eugenej.5584 3 роки тому +1

      @@onthecodeagain I think it's trending this days. A lot of channels make videos about Kafka.

    • @onthecodeagain
      @onthecodeagain  3 роки тому

      @@eugenej.5584 Ive never used it before but ive always want to learn it so I think it will be be a fun one to do. Do you use it?

    • @eugenej.5584
      @eugenej.5584 3 роки тому +1

      @@onthecodeagain Haven't used it in production myself but I heard from multiply developers of high load distributed systems complains about RabbitMQ and that it is hard to make Rabbit work reliably and as a result they switching to Kafka with no regrets :P Main point seems to be that Kafka is fast and has immutable message log that allows you to track bugs without pointing fingers at each other :D Besides, latest Kafka releases don't need Zookeeper (seems to be the biggest pain point).
      An CTO of e-comers chain said that they avoid big part of Kafka complexity by using singe partition per topic and singe provider per topic. This way you know who writes messages and they all ordered (order between partitions not guaranteed).
      Also *Redpanda* seems to be an interesting project.

    • @onthecodeagain
      @onthecodeagain  3 роки тому

      @@eugenej.5584 I'll check out redpanda, I've never used Kafka before so have been doing a bit of research seems to be a nice alternate to RabbitMQ :) think it will make for a promising demo.