0

I am using RabbitMQ to process some jobs in my project. Currently the if i send 5 jobs, lets say

Job1
Job2
Job3
Job4
Job5

All the jobs get delivered to the queue, but if Job1 takes 5 seconds to complete and Job2 takes 2 seconds to complete, the order of execution becomes like

Job5
Job1 etc.,

Is there a way for me to make it so that all these jobs get executed only after the previous one gets completed (Execution flow like Job1, Job2, Job3, Job4, Job5) in RabbitMQ receiver?

Job Execution (as requested by Dave)

var amqp = require('amqplib');

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) {

        //JOB HERE

      }, {noAck: true});

    });

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

thanks, Balan

balanv
  • 10,686
  • 27
  • 91
  • 137

1 Answers1

0

I think you have RabbitMQ server confused with application logic. The short answer is, no you cannot guarantee order of message processing.

To address your clarifying question, the queue cares not about how your application pulls from it. The queue only serves messages to your application. It is up to you how they are processed (e.g. serial, parallel, etc.). I would contend that it does not make much sense to use a message queue if you plan on serial processing only as you get all of the drawbacks of a message server with none of the benefits. Perhaps you could describe your application a bit more?

For additional details, see my other answer at message order of delivery.

Community
  • 1
  • 1
theMayer
  • 15,456
  • 7
  • 58
  • 90
  • I understand that RabbitMQ is to receive and execute operations like Push Notification calls which need not to be executed along with other logics in code.. But for one of my requirement, i wondered if there is a chance to make the queue process request one by one.. – balanv Jan 19 '15 at 08:53