pardahlman / RawRabbit

A modern .NET framework for communication over RabbitMq
MIT License
747 stars 144 forks source link

Message Delaying #223

Closed bartkusters closed 7 years ago

bartkusters commented 7 years ago

I was reading these links and was wondering how to achief this with RawRabbit?

https://www.rabbitmq.com/blog/2015/04/16/scheduling-messages-with-rabbitmq/ or https://github.com/rabbitmq/rabbitmq-delayed-message-exchange

Many thans in advance,

Bart

pardahlman commented 7 years ago

Hello, @bartkusters - thanks for asking!

Looks like the only thing that the client needs to do is to add the x-delay header. Depending on what version you are running (1.x or 2.0) this is done slightly differently.

For 1.x

await client.PublishAsync(new BasicMessage
{
    Prop = "I am important!"
}, configuration: cfg => cfg.WithProperties(p => p.Headers.Add("x-delay", 5000)));

For 2.0

await client.PublishAsync(message, ctx => ctx
    .UsePublisherConfiguration(cfg => cfg
        .WithProperties(p => p.Headers.Add("x-delay", 5000)
    )));

I haven't run the code myself, but hopefully this will get you started. There might be a null pointer exception if Header is not defined, in that case just define it in the WithProperties action.

Hope this helps!

bartkusters commented 7 years ago

Hi Par,

Thanks a lot for your quick reply. I'll give it a try.

Cheers