Advertisement
vitareinforce

amqp di nuxt

Jul 18th, 2018
247
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var amqp = require('amqplib/callback_api')
  2.  
  3. amqp.connect({
  4.   protocol: 'amqp',
  5.   hostname: 'localhost',
  6.   port: 5672,
  7.   username: 'ARmachine',
  8.   password: '12345',
  9.   locale: 'en_US',
  10.   frameMax: 0,
  11.   heartbeat: 0,
  12.   vhost: '/ARX',
  13. }, function(err, conn) {
  14.   if(err) {
  15.     console.log("Error :" + err)
  16.   }
  17.   if(conn) {
  18.     console.log("Creating Channel")
  19.     conn.createChannel(function(err, ch) {
  20.       console.log("Channel Created")
  21.       ch.assertExchange('amq.topic', 'topic', {durable: true});
  22.       console.log("Creating Exchange")
  23.       ch.assertQueue('mqtt.queue', {exclusive: false}, function(err, q) {
  24.         if(err) {
  25.           console.log("Error Queue : " + err)
  26.         }
  27.         if(q) {
  28.           console.log("Creating Queue")
  29.           ch.bindQueue('mqtt.queue', 'amq.topic', 'mqtt.kereta')
  30.           console.log("Waiting")
  31.           ch.consume('mqtt.queue', function(msg) {
  32.             console.log(" [x] %s", msg.content.toString())
  33.           }, {noAck: true})
  34.         }
  35.       })
  36.     })
  37.   }
  38. })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement