Advertisement
Guest User

Untitled

a guest
Mar 18th, 2016
309
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.72 KB | None | 0 0
  1. ##### Working Node.js RabbitMQ client #####
  2.  
  3. var amqp = require('amqplib/callback_api');
  4. amqp.connect('amqp://192.168.99.100', function(err, conn) {
  5. conn.createChannel(function(err, ch) {
  6. var ex = 'data';
  7.  
  8. ch.assertExchange(ex, 'direct', {durable: true});
  9.  
  10. ch.assertQueue('', {exclusive: true}, function(err, q) {
  11. console.log(' [*] Waiting for logs. To exit press CTRL+C');
  12.  
  13. ch.bindQueue(q.queue, ex, 'ALERT');
  14.  
  15. ch.consume(q.queue, function(msg) {
  16. console.log(" [x] %s: '%s'", msg.fields.routingKey, msg.content.toString());
  17. }, {noAck: true});
  18. });
  19. });
  20.  
  21. ##### Non working Clojure RabbitMQ client #####
  22.  
  23. (ns notifications.core
  24. (:gen-class))
  25.  
  26. ;; Import methods from langohr
  27. (require '[langohr.core :as rmq]
  28. '[langohr.channel :as lch]
  29. '[langohr.queue :as lq]
  30. '[langohr.exchange :as le]
  31. '[langohr.consumers :as lc]
  32. '[langohr.basic :as lb])
  33.  
  34. (defn start-consumer
  35. "Starts a consumer bound to the given topic exchange in a separate thread"
  36. [ch topic-name]
  37. (let [queue-name "ALERT"
  38. handler (fn [ch {:keys [content-type delivery-tag type] :as meta} ^bytes payload]
  39. (println (format "received %s" (String. payload "UTF-8"))))]
  40. ;; (lq/declare ch queue-name {:exclusive true :auto-delete false})
  41. (lq/declare ch queue-name {:exclusive true})
  42. (lq/bind ch queue-name topic-name)
  43. (lc/subscribe ch queue-name handler)))
  44.  
  45. (defn -main
  46. "Start RabbitMQ consumer"
  47. [& args]
  48. (let [conn (rmq/connect {:host "192.168.99.100"})
  49. ch (lch/open conn)
  50. ex "data"]
  51. (le/declare ch ex "direct" {:durable true})
  52. (start-consumer ch ex)))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement