Friday 19 May 2017

RabbitMq program is hanging while handling 1 lakh queues. is this the right way to do it?

the code is attached below. my system hangs. is this the right way to create those many channels? any help would be apperciated. thanks.

//RabbitMQ

var amqp = require("amqplib/callback_api");
var time = 0;
var limit = 100000;
amqp.connect("amqp://localhost",function(err,conn){
  if(err){
    console.log('Connection closed-----------error connect');
    return;
  }
  var timer = setInterval(() => {
    time+=1;
    if(time>=limit){
      clearInterval(timer);
    }

    conn.createChannel(function(err,ch){
      if(err){
        console.log('Connection closed-----------error createChannel');
        return;
      }
      var q = "queue_name"+time.toString();
      // console.log(q);
      var msg = "this is the message string!!!";
      ch.assertQueue(q,{durable: false});
      ch.sendToQueue(q,new Buffer(msg),{persistent: false});
      // console.log("time = "+time);
    });
  }, 10);
});



via The-Higgs-Boson

No comments:

Post a Comment