1
votes

In my application I am trying to subscribe 'MyQueue' queue which has bindings to it in 'Rebus' topic exchange basing on your advices using next code:

    async void InitializeBus()
    {

    var busConfigurer = Configure.With(new CastleWindsorContainerAdapter(_container))
            .Logging(l => l.Log4Net())
            .Transport(t => t.UseRabbitMq(_connectionString, "MyQueue")
                .Declarations(false, false, false)
                    .ExchangeNames("RebusDirect", "Rebus")
                        .Prefetch(5))
            .Options(o => {
                o.SimpleRetryStrategy(_errorQueue);
                if (_enableLegacyCompatibility)
                {
                    o.EnableLegacyCompatibility();
                }
            })
            .Serialization(s => s.Decorate(c => new XmlMessageSerializer()));

        var bus = busConfigurer.Start();`
        await bus.Advanced.Topics.Subscribe("MyQueue");
    }

as a result i have an exception like

The AMQP operation was interrupted: AMQP close-reason, initiated by Peer, code=404, text="NOT_FOUND - no queue 'MyQueue' in vhost '/'", classId=50, methodId=20, cause=

although the queue exists.

If I remove .Declarations(false, false, false) and await bus.Advanced.Topics.Subscribe("MyQueue"); it will create new MyQueue in rabbit in RebusDirect exchange and start listening to it. Connection string to rabbit is correct.

Where the problem could be? Improper configuration or incorrect subscription way?

Thanks in advance.

1

1 Answers

1
votes

First thing - you should probably only skip automatically declaring things if you are an expert Rebus and RabbitMQ user and there is something out-of-the-ordinary that you want to achieve.

There the Declarations part should probable be .Declarations(true, true, true) (or simply left out because the default is to always ensure that exchanges, queues, and bindings are automatically declared).

Next thing - the line

await bus.Advanced.Topics.Subscribe("MyQueue");

indicates that you are confusing things, because MyQueue is a queue, but when you Subscribe to something, you subscribe to a TOPIC.

A "topic" is basically just an arbitrary string, e.g. "thingamabob". A publisher can publish things using that topic like this:

await bus.Advanced.Topics.Publish("thingamabob", new GizmoDoodle());

which will then deliver the GizmoDoodle message to the queues currently bound to that topic.

In order to "bind to the topic", you

await bus.Advanced.Topics.Subscribe("thingamabob");

which establishes the binding in RabbitMQ.

I suggest you start out with a clean slate (without customizing Rebus' use of RabbitMQ in any way) and go see what Rebus creates in RabbitMQ to make it work. And if you haven't done it already, you definitely should go enable the RabbitMQ Management Plugin.