Advertisement
Guest User

Clojure-RabbitMQ

a guest
Mar 21st, 2016
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. ;; Import methods from langohr
  2. (require '[langohr.core :as rmq]
  3. '[langohr.channel :as lch]
  4. '[langohr.queue :as lq]
  5. '[langohr.exchange :as le]
  6. '[langohr.consumers :as lc]
  7. '[langohr.basic :as lb])
  8.  
  9. (defn start-alert-consumer
  10. "Starts a consumer bound to the given topic exchange in a separate thread"
  11. [ch ex]
  12. (let [queue "ALERT"
  13. handler (fn [ch {:keys [content-type delivery-tag type] :as meta} ^bytes payload]
  14. (println (format "received %s" (String. payload "UTF-8"))))]
  15. (lq/declare ch queue))
  16. (lq/bind ch queue ex)
  17. (lc/subscribe ch queue handler)))
  18.  
  19. (defn -main
  20. "Start RabbitMQ consumer"
  21. [& args]
  22. (let [conn (rmq/connect {:host "192.168.99.101"})
  23. ch (lch/open conn)
  24. ex "data"]
  25. (le/declare ch ex "direct" {:durable true})
  26. (start-alert-consumer ch ex)))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement