Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

EasyNetQ. Advanced API - Publish does not produce response on RabbitServer

Looking at EasyNetQ as replacement for our current library for MQ communication.

For Testing im trying to simply publish a number of messages to an exchange, using a custom naming strategy. My method for publishing is in t he small test method below>

public void PublishTest()
{
    var advancedBus = RabbitHutch.CreateBus("host=localhost;virtualHost=Test;username=guest;password=guest;").Advanced;
    var routingKey = "SimpleMessage";

    // declare some objects
    var queue = advancedBus.QueueDeclare("Q.TestQueue.SimpleMessage");
    var exchange = advancedBus.ExchangeDeclare("E.TestExchange.SimpleMessage", ExchangeType.Direct);
    var binding = advancedBus.Bind(exchange, queue, routingKey);

    var message = new SimpleMessage() {Test = "HELLO"};
    for (int i = 0; i < 100; i++)
    {
        advancedBus.Publish(exchange, routingKey, true, true, new Message<SimpleMessage>(message));
    }
    advancedBus.Dispose();
}

The problem is that even thou the Exchange and Queue is created, and bound proper, publishing does not produce anything. No messages hit the queue. The graph in the Rabbit MQ management interface does not even show any activity on the exchange. Am i missing something here? The code is basically taken straight from the documentation.

If im using the simple bus and simply just publish, an exchange is created and i can see via the management interface, that messages are being published. Since the simple bus uses the advanced API to publish i assume that it is a setup issue that i am missing.

I hope someone can bring some insight:-)

/Thomas

like image 483
ThBlitz Avatar asked Feb 22 '14 13:02

ThBlitz


1 Answers

I finally tracked down what was causing the problem. It turns out that setting the parameter: immediate to true will cause the systems to throw exceptions. the paramters is apparently not supported any more in the RabbitMQ client, see the discussion here: https://github.com/mikehadlow/EasyNetQ/issues/112

So the code below works just fine, mark the change from true to false in the publish method:

public void PublishTest()
{
    var advancedBus = RabbitHutch.CreateBus("host=localhost;virtualHost=Test;username=guest;password=guest;").Advanced;
    var routingKey = "SimpleMessage";

    // declare some objects
    var queue = advancedBus.QueueDeclare("Q.TestQueue.SimpleMessage");
    var exchange = advancedBus.ExchangeDeclare("E.TestExchange.SimpleMessage", ExchangeType.Direct);
    var binding = advancedBus.Bind(exchange, queue, routingKey);

    var message = new SimpleMessage() {Test = "HELLO"};
    for (int i = 0; i < 100; i++)
    {
        advancedBus.Publish(exchange, routingKey, true, false, new Message<SimpleMessage>(message));
    }
    advancedBus.Dispose();
}
like image 141
ThBlitz Avatar answered Sep 30 '22 20:09

ThBlitz