Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ##### Working Node.js RabbitMQ client #####
- var amqp = require('amqplib/callback_api');
- amqp.connect('amqp://192.168.99.100', function(err, conn) {
- conn.createChannel(function(err, ch) {
- var ex = 'data';
- ch.assertExchange(ex, 'direct', {durable: true});
- ch.assertQueue('', {exclusive: true}, function(err, q) {
- console.log(' [*] Waiting for logs. To exit press CTRL+C');
- ch.bindQueue(q.queue, ex, 'ALERT');
- ch.consume(q.queue, function(msg) {
- console.log(" [x] %s: '%s'", msg.fields.routingKey, msg.content.toString());
- }, {noAck: true});
- });
- });
- ##### Non working Clojure RabbitMQ client #####
- (ns notifications.core
- (:gen-class))
- ;; Import methods from langohr
- (require '[langohr.core :as rmq]
- '[langohr.channel :as lch]
- '[langohr.queue :as lq]
- '[langohr.exchange :as le]
- '[langohr.consumers :as lc]
- '[langohr.basic :as lb])
- (defn start-consumer
- "Starts a consumer bound to the given topic exchange in a separate thread"
- [ch topic-name]
- (let [queue-name "ALERT"
- handler (fn [ch {:keys [content-type delivery-tag type] :as meta} ^bytes payload]
- (println (format "received %s" (String. payload "UTF-8"))))]
- ;; (lq/declare ch queue-name {:exclusive true :auto-delete false})
- (lq/declare ch queue-name {:exclusive true})
- (lq/bind ch queue-name topic-name)
- (lc/subscribe ch queue-name handler)))
- (defn -main
- "Start RabbitMQ consumer"
- [& args]
- (let [conn (rmq/connect {:host "192.168.99.100"})
- ch (lch/open conn)
- ex "data"]
- (le/declare ch ex "direct" {:durable true})
- (start-consumer ch ex)))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement