File tree Expand file tree Collapse file tree 2 files changed +44
-0
lines changed
clojure/src/rabbitmq/tutorials Expand file tree Collapse file tree 2 files changed +44
-0
lines changed Original file line number Diff line number Diff line change 1+ (ns rabbitmq.tutorials.emit-log
2+ (:require [langohr.core :as lc]
3+ [langohr.channel :as lch]
4+ [langohr.exchange :as le]
5+ [langohr.basic :as lb]
6+ [clojure.string :as s]))
7+
8+ (def ^{:const true } x " logs" )
9+
10+ (defn -main
11+ [& args]
12+ (with-open [conn (lc/connect )]
13+ (let [ch (lch/open conn)
14+ payload (if (empty? args)
15+ " Hello, world!"
16+ (s/join " " args))]
17+ (le/fanout ch x :durable false :auto-delete false )
18+ (lb/publish ch x " " payload)
19+ (println (format " [x] Sent %s" payload)))))
Original file line number Diff line number Diff line change 1+ (ns rabbitmq.tutorials.receive-logs
2+ (:require [langohr.core :as lc]
3+ [langohr.channel :as lch]
4+ [langohr.exchange :as le]
5+ [langohr.queue :as lq]
6+ [langohr.basic :as lb]
7+ [langohr.consumers :as lcons]))
8+
9+ (def ^{:const true } x " logs" )
10+
11+ (defn handle-delivery
12+ " Handles message delivery"
13+ [ch metadata payload]
14+ (println (format " [x] %s" (String. payload " UTF-8" ))))
15+
16+
17+ (defn -main
18+ [& args]
19+ (with-open [conn (lc/connect )]
20+ (let [ch (lch/open conn)
21+ {:keys [queue]} (lq/declare ch " " :durable true :auto-delete false )]
22+ (le/fanout ch x :durable false :auto-delete false )
23+ (lq/bind ch queue x)
24+ (println " [*] Waiting for logs. To exit press CTRL+C" )
25+ (lcons/blocking-subscribe ch queue handle-delivery))))
You can’t perform that action at this time.
0 commit comments