balanv
balanv

Reputation: 10888

RabbitMQ - The receiver receives only 14 message at a time

I have been using RabbitMQ for one of my nodejs projects. I use the below code format for sender/receiver

Sender :

#!/usr/bin/env node
var amqp = require('amqplib');
var when = require('when');

for(loop=1; loop<30; loop++){

  amqp.connect('amqp://localhost').then(function(conn) {
    return when(conn.createChannel().then(function(ch) {
      var q = 'hello';
      var msg = {'status':'success', 'message': 'Hello World!'};

      var ok = ch.assertQueue(q, {durable: false});

      return ok.then(function(_qok) {

          ch.sendToQueue(q, new Buffer("Message"), { headers: { 'device_token' : "321654987" } });
          console.log(" [x] Sent '%s'", msg);
          return ch.close();

      });
    })).ensure(function() { conn.close(); });;
  }).then(null, console.warn);
}

Receiver :

var Bitstamp = require('../bitstamp.js');
var count = 0;
var amqp = require('amqplib');
var common_options = {noAck: false, maxLength: 500 };

amqp.connect('amqp://localhost').then(function(conn) {
  process.once('SIGINT', function() { conn.close(); });
  return conn.createChannel().then(function(ch) {

    var ok = ch.assertQueue('hello', {durable: false});

    ok = ok.then(function(_qok) {
      return ch.consume('hello', function(msg) {
        count ++;
        console.log("Received Message : "+count);

      }, common_options); 

    });

    return ok.then(function(_consumeOk) {
      console.log(' [*] Waiting for messages. To exit press CTRL+C');
    });
  });
}).then(null, console.warn);


function parseResult(data){
  return JSON.stringify(data);
}

But i always receive only 14 messages in the receiver end, even though i send more messages in a loop. I guess there could be a limit in number of messages being sent to receiver? Please suggest.

Upvotes: 0

Views: 252

Answers (2)

balanv
balanv

Reputation: 10888

I got the answer!

The issue was related to the message bytes configuration, i have set it as like below and the issue is fixed

var common_options = {noAck: true, maxLength: 500, messageBytes: 10000000000 };

Now i can send more messages per second.

Upvotes: 0

Reece
Reece

Reputation: 764

I just ran that code and got 29 messages to the receiver, did you have multiple receivers running at the same time?

Rabbitmq would round-robin the messages across any receivers running (connected to the queue)

Upvotes: 1

Related Questions