Tutorial 3 in Clojure

This commit is contained in:
Michael Klishin 2013-08-05 02:34:04 +04:00
parent e6fe8e3b96
commit db3e3e6d50
2 changed files with 44 additions and 0 deletions

View 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)))))

View 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))))