Advertisement
vitareinforce

AMQP Testing ga konek

Jul 17th, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import amqp from 'amqplib/callback_api'
  2.  
  3. amqp.connect('amqp://ARmachine:12345@localhost:5672/ARX', function(err, conn) {
  4.     if (err) {
  5.       console.error("[AMQP]", err.message)
  6.     } else {
  7.       console.log("[AMQP] connected")
  8.       conn.createChannel(function(err, ch) {
  9.         if (err) {
  10.           console.error("[AMQP]", err.message);
  11.         } else {
  12.           console.log("[AMQP] Channel" + ch)
  13.           ch.assertExchange('amq.topic', 'topic', {durable: true})
  14.           console.log("[AMQP] Create Exchange")
  15.           ch.assertQueue('mqtt.queue', {exclusive: true}, function(err, q) {
  16.             console.log(" [*] Waiting for messages in %s. To exit press CTRL+C", q.queue)
  17.             ch.bindQueue('mqtt.queue', 'amq.topic', 'mqtt.kereta')
  18.  
  19.             ch.consume(q.queue, function(msg) {
  20.               console.log(" [x] %s", msg.content.toString())
  21.             }, {noAck: true})
  22.           });
  23.         }
  24.       })
  25.     }
  26.   });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement