Skip to content

Instantly share code, notes, and snippets.

@alexanderjamesking
Created June 1, 2014 21:34
Show Gist options
  • Save alexanderjamesking/5b3b7bcd1bb6d681778d to your computer and use it in GitHub Desktop.
Save alexanderjamesking/5b3b7bcd1bb6d681778d to your computer and use it in GitHub Desktop.
Clojure and RabbitMQ
; to be run in lein repl
(require 'langohr.core)
(require '[langohr.queue :as lq])
(require '[langohr.basic :as lb])
(require '[langohr.consumers :as lc])
; langohr.core/*default-config*
; default port is 5672 - running on 5004 as it is forwarded to rabbitmq on docker
(def conn (langohr.core/connect {:hostname "localhost" :port 5004}))
(def ch (langohr.channel/open conn))
(def ingest-queue "ingest")
; create the queue
(lq/declare ch ingest-queue)
(defn publish-handler [ch metadata ^bytes payload]
(let [d (String. payload "UTF-8")]
(println d)))
; subscribe to the queue
(def publish (lc/subscribe ch ingest-queue publish-handler))
; send some test messages
(doseq [x (range 1 200)] (lb/publish ch "" ingest-queue (str "message: " x)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment