Advertisement
Guest User

Untitled

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