0

I am working on a project that requires the usage of a few rabbitmq queues. One of the queues requires that the messages are delayed for processing at a time in the future. I noticed in the documentation for rabbmitmq there is a new plugin called RabbitMQ Delayed Message Plugin that seems to allow this functionality. In the past for rabbmitmq based projects, I used seneca-amqp-transport for message adding and processing. The issue is that I have not seen any documentation for seneca or been able to find any examples outlining how to add header properties.

It seems as if I need to initially make sure the queue is created with x-delayed-type. Additionally, as each message is added to the queue, I need to make sure the x-delay header parameter is added to the message before it is sent to rabbbitmq. Is there a way to pass this parameter, x-delay, with seneca-amqp-transport?

Here is my current code for adding a message to the queue:

return new Promise((resolve, reject) => {
    const client = require('seneca')()
        .use('seneca-amqp-transport')
        .client({
            type: 'amqp',
            pin: 'action:perform_time_consuming_act',
            url: process.env.AMQP_SEND_URL
        }).ready(() => {
            client.act('action:perform_time_consuming_act', {
                message: {data: 'this is a test'}
            }, (err, res) => {
                if (err) {
                    reject(err);
                }

                resolve(true);
            });
        });
}

In the code above, where would header-related data go?

user1790300
  • 2,143
  • 10
  • 54
  • 123

1 Answers1

0

I just looked up the code of the library and under lib/client/publisher.js , this should do the trick

function publish(message, exchange, rk, options) {
const opts = Object.assign({}, options, {
  replyTo: replyQueue,
  contentType: JSON_CONTENT_TYPE,
  x-delay: 5000,
  correlationId: correlationId
});
return ch.publish(exchange, rk, Buffer.from(message), opts);

}

Give it a Try , should work. Here the delay value if set to 5000 milliseconds. You can also overload the publish method to take the value as a parameter.

Soumen Mukherjee
  • 2,953
  • 3
  • 22
  • 34