forked from rnewman/clojure-rabbitmq
/
consumer.clj
35 lines (25 loc) · 923 Bytes
/
consumer.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
27
28
29
30
31
32
33
34
(ns rabbitmq.consumer.test
(:require [com.github.icylisper.rabbitmq :as rabbitmq]))
(defonce conn-map {:username "guest"
:password "guest"
:host "localhost"
:port 5672
:virtual-host "/"
:type "direct"
:exchange "sorting-room"
:queue "po-box"
:routing-key "tata"})
(defonce connection (rabbitmq/connect conn-map))
(def c (ref 0))
(while true
(dosync (alter c inc))
(println "cycle: " @c)
;; publish
(let [[_ channel] connection
message (rabbitmq/consume-poll conn-map channel)]
(println "rabbitmq consumer : got message" message))
(Thread/sleep 1000))
;; (let [[_ channel] connection]
;; (println (rabbitmq/consume-poll conn-map channel)))
;; (let [[conn channel] connection]
;; (println (rabbitmq/queue-seq channel conn-map)))