forked from rabbitmq/rabbitmq-tutorials
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreceive_logs_topic.clj
26 lines (22 loc) · 905 Bytes
/
receive_logs_topic.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
(ns rabbitmq.tutorials.receive-logs-topic
(: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 "topic_logs")
(defn handle-delivery
"Handles message delivery"
[ch {:keys [routing-key]} payload]
(println (format " [x] %s:%s" routing-key (String. payload "UTF-8"))))
(defn -main
[& args]
(with-open [conn (lc/connect)]
(let [ch (lch/open conn)
{:keys [queue]} (lq/declare ch "" :durable false :auto-delete false)]
(le/topic ch x :durable false :auto-delete false)
(doseq [severity args]
(lq/bind ch queue x :routing-key severity))
(println " [*] Waiting for logs. To exit press CTRL+C")
(lcons/blocking-subscribe ch queue handle-delivery))))