Setting up and using RabbitMQ Delayed Exchange plugin via C#

756 views
Skip to first unread message

Steve Reddy

unread,
Jan 18, 2016, 2:31:56 PM1/18/16
to rabbitmq-users
Hey guys,

Has anyone set up and successfully sent messages to a delayed exchange queue via a C# app or service? I'm trying to "translate" the instructions found here "https://github.com/rabbitmq/rabbitmq-delayed-message-exchange/
into the format of the C# client, i.e.: 

channel.ExchangeDeclare("rulesengine", ExchangeType.Direct);

            //this will create the queue if it doesn't already exist
            channel.QueueDeclare(queue: queueName,
                durable: true,
                exclusive: false,
                autoDelete: false,
                arguments: null);

            //and this will bind the exchange to the queue via a specific routing key
            channel.QueueBind(queueName, "rulesengine", queueName, null);

channel.BasicPublish(exchange: "rulesengine",
                                         routingKey: "failedconfirmations",
                                         basicProperties: null,
                                         body: transactionBuffer);

I'll keep toying with it. In the meantime, if anyone has any tips of examples of this being done, I'd really appreciate it!

Thanks,
Steve

Alvaro Videla

unread,
Jan 18, 2016, 2:35:12 PM1/18/16
to rabbitm...@googlegroups.com
As the example shows, the exchange has to be declared with the "x-delayed-type".  Also you need to pass arguments to the exchange declare call specifying the 'x-delayed-type', like 'direct', 'fanout', and so on.

--
You received this message because you are subscribed to the Google Groups "rabbitmq-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rabbitmq-user...@googlegroups.com.
To post to this group, send email to rabbitm...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Steve Reddy

unread,
Jan 18, 2016, 3:13:29 PM1/18/16
to rabbitmq-users
Ok. The declare wasn't hard to translate to C#. This looks right:
             var args = new Dictionary<String, Object> {{"x-delayed-type", "direct"}};
            channel.ExchangeDeclare("rulesenginedelay", "x-delayed-type", true, false, args);

But translating the next example from the plugin instructions into a C# BasicPublish looks a little trickier. Basically looks like I just need to build another Dictionary and plug it into the basicProperties parameter... 

Thanks Alvaro. Sorry to hear you're leaving the community. 

Steve Reddy

unread,
Jan 18, 2016, 3:36:57 PM1/18/16
to rabbitmq-users
Ok I do have one question though. In the example, they use this line to build the properties object:

AMQP.BasicProperties.Builder props = new AMQP.BasicProperties.Builder().headers(headers);

But I don't seem to have that AMQP static object in the rabbitMQ library for C#. What alternative should I be using? Or am I perhaps missing a reference in my project? 

On Monday, January 18, 2016 at 1:31:56 PM UTC-6, Steve Reddy wrote:

Steve Reddy

unread,
Jan 18, 2016, 3:57:28 PM1/18/16
to rabbitmq-users
This looks like maybe what I'm supposed to do... 

                    var headers = new Dictionary<string, object>();
                    headers.Add("x-delay", 900000); //this will delay the message by 15 minutes before it's re-queued to the transactions queue
                    
                    IBasicProperties props = channel.CreateBasicProperties();
                    props.Headers = headers;

                    channel.BasicPublish(exchange: "rulesengine",
                                         routingKey: "failedtransactions",
                                         basicProperties: props,
                                         body: transactionBuffer);

On Monday, January 18, 2016 at 1:31:56 PM UTC-6, Steve Reddy wrote:

Michael Klishin

unread,
Jan 18, 2016, 4:10:05 PM1/18/16
to rabbitm...@googlegroups.com, Steve Reddy
On 18 January 2016 at 23:57:31, Steve Reddy (sred...@gmail.com) wrote:
> IBasicProperties props = channel.CreateBasicProperties();
> props.Headers = headers;
>
> channel.BasicPublish(exchange: "rulesengine",
> routingKey: "failedtransactions",
> basicProperties: props,
> body: transactionBuffer);

Correct. We’d certainly welcome a PR to the .NET API guide to provide a small example.

And perhaps we should use IModel.CreateBasicProperties in
https://github.com/rabbitmq/rabbitmq-dotnet-client/blob/master/projects/client/Unit/src/unit/TestBasicProperties.cs
--
MK

Staff Software Engineer, Pivotal/RabbitMQ


Reply all
Reply to author
Forward
0 new messages