Skip to content

Prioritizing messages? #30

@markohaapala

Description

@markohaapala

Hi,

I've struggled with getting messages prioritized in RabbitMQ using Rabbus send-receive pattern. I create the exchange like this:

  1 'use strict';
  2 var util = require('../util/util');
  3 var Rabbus = require('rabbus');
  4 var rabbot = require('rabbot');
  5 
  6 function NewPaymentReceiver(limit) {
  7   var options = {
  8     exchange: 'payment.ex',
  9     routingKey: 'payment.new',
 10     queue: {
 11       name: 'payment.q',
 12       noBatch: true,
 13       limit: Number(limit), // Here I've tried values 1 and 20
 14       maxPriority: 4
 15     }
 16   };
 17   Rabbus.Receiver.call(this, rabbot, options);
 18 }
 19 
 20 util.inherits(NewPaymentReceiver, Rabbus.Receiver);
 21 module.exports = NewPaymentReceiver;

And in the Sender I set a priority in the middleware depending on how the Sender was initialized:

[...]
  5 exports.payment = function(priority) {
  6   priority = priority ? priority : 1; // LOW 0, NORMAL 1, HIGH 2, "REALTIME" 3, "REALTIME" ENRICHED 4
[...]
 14   var newPaymentSender = new NewPaymentSender();
 15 
 16   newPaymentSender.use(function(message, headers, next) {
 17     headers['x-priority'] = priority;
 18     next();
 19   });
[...]

I can see in RabbitMQ console that the queue has x-max-priority set to 4, and in the messages I see the header x-priority as 1 or 2, depending on how the Sender was initialized.

The queue will however be processed sequentially in the order that the payments are received. My guess is that I'm missing something fundamental. Other than configuring the exchange, I couldn't find any references of defining message priorities in RabbitMQ layout book, RMQ Patterns book, rabbus source code or through google, so this is my last hope to get some guidance.

EDIT: I'm using

  • RabbitMQ 3.6.1
  • Rabbus 0.8.2
  • Rabbot 1.0.6

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions