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

1

7

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

Confined answered 22/2, 2014 at 13:18 Comment(0)
C
9

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();
}
Confined answered 22/2, 2014 at 14:16 Comment(1)
THANK YOU! I Just lost an hour to this.Insult

© 2022 - 2024 — McMap. All rights reserved.