Tutorial 3 in Clojure
This commit is contained in:
parent
e6fe8e3b96
commit
db3e3e6d50
19
clojure/src/rabbitmq/tutorials/emit_log.clj
Normal file
19
clojure/src/rabbitmq/tutorials/emit_log.clj
Normal file
@ -0,0 +1,19 @@
|
||||
(ns rabbitmq.tutorials.emit-log
|
||||
(:require [langohr.core :as lc]
|
||||
[langohr.channel :as lch]
|
||||
[langohr.exchange :as le]
|
||||
[langohr.basic :as lb]
|
||||
[clojure.string :as s]))
|
||||
|
||||
(def ^{:const true} x "logs")
|
||||
|
||||
(defn -main
|
||||
[& args]
|
||||
(with-open [conn (lc/connect)]
|
||||
(let [ch (lch/open conn)
|
||||
payload (if (empty? args)
|
||||
"Hello, world!"
|
||||
(s/join " " args))]
|
||||
(le/fanout ch x :durable false :auto-delete false)
|
||||
(lb/publish ch x "" payload)
|
||||
(println (format " [x] Sent %s" payload)))))
|
25
clojure/src/rabbitmq/tutorials/receive_logs.clj
Normal file
25
clojure/src/rabbitmq/tutorials/receive_logs.clj
Normal file
@ -0,0 +1,25 @@
|
||||
(ns rabbitmq.tutorials.receive-logs
|
||||
(:require [langohr.core :as lc]
|
||||
[langohr.channel :as lch]
|
||||
[langohr.exchange :as le]
|
||||
[langohr.queue :as lq]
|
||||
[langohr.basic :as lb]
|
||||
[langohr.consumers :as lcons]))
|
||||
|
||||
(def ^{:const true} x "logs")
|
||||
|
||||
(defn handle-delivery
|
||||
"Handles message delivery"
|
||||
[ch metadata payload]
|
||||
(println (format " [x] %s" (String. payload "UTF-8"))))
|
||||
|
||||
|
||||
(defn -main
|
||||
[& args]
|
||||
(with-open [conn (lc/connect)]
|
||||
(let [ch (lch/open conn)
|
||||
{:keys [queue]} (lq/declare ch "" :durable true :auto-delete false)]
|
||||
(le/fanout ch x :durable false :auto-delete false)
|
||||
(lq/bind ch queue x)
|
||||
(println " [*] Waiting for logs. To exit press CTRL+C")
|
||||
(lcons/blocking-subscribe ch queue handle-delivery))))
|
Loading…
Reference in New Issue
Block a user