Advertisement
lompo777

Untitled

Jun 14th, 2021
516
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/env node
  2.  
  3. var amqp = require('amqplib/callback_api');
  4. amqp.connect('amqp://miguel:miguel123@152.228.133.222:32777/mobile_app', function(error0, connection) {
  5.   if (error0) {
  6.     throw error0;
  7.   }
  8.   connection.createChannel(function(error1, channel) {
  9.     if (error1) {
  10.       throw error1;
  11.     }
  12.     var exchange = 'crowd_sensing_exchange';
  13.     var severity = 'crowd_sensing';
  14.  
  15.  
  16.     var JsonMsg={
  17.       "user_id": "1",
  18.       "device_id":"sabri test",
  19.       "datetime":"10-22-2020 15:21:50",
  20.       "location":{
  21.           "lat":43.48,
  22.           "lng":-1.49    
  23.       },
  24.       "sensors":{
  25.           "temperature":"sabri test connection"
  26.       }
  27.     }
  28.  
  29.     var msg = JSON.stringify(JsonMsg);
  30.  
  31.     channel.publish(exchange, severity, Buffer.from(msg));
  32.     console.log(" [x] Sent %s: '%s'", severity, msg);
  33.  
  34.   });
  35.  
  36.   setTimeout(function() {
  37.     connection.close();
  38.     process.exit(0)
  39.   }, 10000);
  40. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement