Created
January 4, 2013 02:29
-
-
Save boxxxie/4449412 to your computer and use it in GitHub Desktop.
trying to get (println)s printing to the same repl output
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (ns api.rabbitmq | |
| (:gen-class) | |
| (:require [langohr.core :as rmq] | |
| [langohr.channel :as lch] | |
| [langohr.queue :as lq] | |
| [langohr.consumers :as lc] | |
| [langohr.basic :as lb])) | |
| (def ^{:const true} | |
| default-exchange-name "") | |
| (defn message-handler | |
| [ch {:keys [content-type delivery-tag type] :as meta} ^bytes payload] | |
| (println (format "[consumer] Received a message: %s, delivery tag: %d, content type: %s, type: %s" | |
| (String. payload "UTF-8") delivery-tag content-type type))) | |
| (defn start-consumer | |
| "Starts a consumer in a separate thread" | |
| [conn ch queue-name] | |
| (let [thread (Thread. (bound-fn [] | |
| (lc/subscribe ch queue-name message-handler :auto-ack true)))] | |
| (.start thread))) | |
| (defn -main | |
| [& args] | |
| (let [conn (rmq/connect) | |
| ch (lch/open conn) | |
| qname "langohr.examples.hello-world"] | |
| (println (format "[main] Connected. Channel id: %d" (.getChannelNumber ch))) | |
| (lq/declare ch qname :exclusive false :auto-delete true) | |
| (start-consumer conn ch qname) | |
| (lb/publish ch default-exchange-name qname "Hello!" :content-type "text/plain" :type "greetings.hi") | |
| (Thread/sleep 2000) | |
| (println "[main] Disconnecting...") | |
| (rmq/close ch) | |
| (rmq/close conn))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment