Skip to content

Commit db3e3e6

Browse files
author
Michael Klishin
committed
Tutorial 3 in Clojure
1 parent e6fe8e3 commit db3e3e6

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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)))))
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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))))

0 commit comments

Comments
 (0)