Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

updated the code so that each function name is unique. This should al…

…low me to create a single main function to run the samples from the command line
  • Loading branch information...
commit 672c4de313cbec81529247a004c2ee6246ad674a 1 parent 398015e
Rob Rowe authored
17 src/tutorial/helloworld.clj
@@ -8,9 +8,9 @@
8 8 ;----------------------
9 9 ; Producer portion
10 10 ;----------------------
11   -(defn producer
  11 +(defn helloworld-producer
12 12 []
13   - (with-broker {:host "localhost" :username "idiscc" :password "1d15cc"}
  13 + (with-broker con-info
14 14 (with-channel
15 15 (create-queue queuename)
16 16 (create-exchange exchangename "fanout")
@@ -23,10 +23,19 @@
23 23 ;----------------------
24 24 ; Consumer portion
25 25 ;----------------------
26   -(defn consumer
  26 +(defn helloworld-consumer
27 27 []
28   - (with-broker {:host "localhost" :username "idiscc" :password "1d15cc"}
  28 + (with-broker con-info
29 29 (with-channel
30 30 (with-queue queuename
31 31 (doseq [msg (consuming-seq true)]
32 32 (println "received: " (String. (:body msg))))))))
  33 +
  34 +
  35 +(defn run-helloworld []
  36 + (helloworld-producer)
  37 + (helloworld-producer)
  38 + (helloworld-producer)
  39 +
  40 + ;We now have 3 messages queued up so lets 'consume' them
  41 + (helloworld-consumer))
10 src/tutorial/pubsub.clj
@@ -14,8 +14,7 @@
14 14 ;----------------------
15 15 ; Producer portion
16 16 ;----------------------
17   -(defn emit-log
18   - []
  17 +(defn pubsub-producer []
19 18 (with-broker con-info
20 19 (with-channel
21 20 (create-exchange exchangename "fanout")
@@ -25,8 +24,7 @@
25 24 ;----------------------
26 25 ; Consumer portion
27 26 ;----------------------
28   -(defn receive-logs
29   - []
  27 +(defn pubsub-consumer []
30 28 (with-broker con-info
31 29 (with-channel
32 30 (def queuename (.queue (queue-declare)))
@@ -37,3 +35,7 @@
37 35 (println "received: " body)
38 36 (println "routing-key: " (:routing-key (:envelope msg)))
39 37 (ack (:delivery-tag (:envelope msg)))))))))
  38 +
  39 +(defn run-pubsub []
  40 + (pubsub-producer)
  41 + (pubsub-consumer))
6 src/tutorial/queue.clj
... ... @@ -1,11 +1,11 @@
1 1 (ns tutorial.queue
2 2 (:use com.mefesto.wabbitmq))
3 3
4   -(def con-info {:host "localhost" :username "idiscc" :password "1d15cc"})
  4 +(def con-info {:host "localhost" :username "guest" :password "guest"})
5 5
6 6 (defn delete-queue
7 7 [queue-name exchange-name]
8   - (with-broker {:host "localhost" :username "idiscc" :password "1d15cc"}
  8 + (with-broker con-info
9 9 (with-channel
10 10 (if (not (= "" exchange-name)) (exchange-delete exchange-name))
11 11 (queue-delete queue-name))))
@@ -21,6 +21,4 @@
21 21 ([name] (exchange-declare name "fanout"))
22 22 ([name type] (exchange-declare name type)))
23 23
24   -(defn delete-hello-world-queue []
25   - (delete-queue "text.exchange" "test.queue"))
26 24
12 src/tutorial/routing.clj
@@ -14,8 +14,7 @@
14 14 ;----------------------
15 15 ; Producer portion
16 16 ;----------------------
17   -(defn emit-log-direct
18   - []
  17 +(defn routing-producer []
19 18 (with-broker con-info
20 19 (with-channel
21 20 (create-exchange exchangename "direct")
@@ -28,17 +27,20 @@
28 27 ;----------------------
29 28 ; Consumer portion
30 29 ;----------------------
31   -(defn receive-logs-direct
32   - []
  30 +(defn routing-consumer []
33 31 (with-broker con-info
34 32 (with-channel
35 33 (def queuename (.queue (queue-declare)))
36 34 (queue-bind queuename exchangename error-routing-key)
37 35 (queue-bind queuename exchangename warning-routing-key)
38   - ;(queue-bind queuename exchangename info-routing-key)
  36 + (queue-bind queuename exchangename info-routing-key)
39 37 (with-queue queuename
40 38 (doseq [msg (consuming-seq false)]
41 39 (let [body (String. (:body msg))]
42 40 (println "received: " body)
43 41 (println "routing-key: " (:routing-key (:envelope msg)))
44 42 (ack (:delivery-tag (:envelope msg)))))))))
  43 +
  44 +(defn run-routing []
  45 + (routing-producer)
  46 + (routing-consumer))
9 src/tutorial/topic.clj
@@ -15,8 +15,7 @@
15 15 ;----------------------
16 16 ; Producer portion
17 17 ;----------------------
18   -(defn emit-log-topic
19   - []
  18 +(defn topic-producer []
20 19 (with-broker con-info
21 20 (with-channel
22 21 (create-exchange exchangename "topic")
@@ -29,7 +28,7 @@
29 28 ;----------------------
30 29 ; Consumer portion
31 30 ;----------------------
32   -(defn receive-logs-topic
  31 +(defn topic-consumer
33 32 []
34 33 (with-broker con-info
35 34 (with-channel
@@ -42,3 +41,7 @@
42 41 (println "received: " body)
43 42 (println "routing-key: " (:routing-key (:envelope msg)))
44 43 (ack (:delivery-tag (:envelope msg)))))))))
  44 +
  45 +(defn run-topic []
  46 + (topic-producer)
  47 + (topic-consumer))
13 src/tutorial/workqueues.clj
@@ -16,9 +16,9 @@
16 16 ;----------------------
17 17 ; Producer portion
18 18 ;----------------------
19   -(defn producer
  19 +(defn workqueues-producer
20 20 []
21   - (with-broker {:host "localhost" :username "idiscc" :password "1d15cc"}
  21 + (with-broker con-info
22 22 (with-channel
23 23 (qos 1)
24 24 (create-queue queuename)
@@ -40,9 +40,9 @@
40 40 [task]
41 41 (. Thread (sleep (* 1000 (count (re-find #"\.+" task))))))
42 42
43   -(defn consumer
  43 +(defn workqueues-consumer
44 44 []
45   - (with-broker {:host "localhost" :username "idiscc" :password "1d15cc"}
  45 + (with-broker con-info
46 46 (with-channel
47 47 (with-queue queuename
48 48 (doseq [msg (consuming-seq false)]
@@ -51,3 +51,8 @@
51 51 (work body)
52 52 (println ".Done!")
53 53 (ack (:delivery-tag (:envelope msg)))))))))
  54 +
  55 +
  56 +(defn run-workqueues []
  57 + (workqueues-producer)
  58 + (workqueues-consumer))

0 comments on commit 672c4de

Please sign in to comment.
Something went wrong with that request. Please try again.