RawRabbit icon indicating copy to clipboard operation
RawRabbit copied to clipboard

Confused about binding between exchange and queues

Open charconstpointer opened this issue 5 years ago • 2 comments

var client = RawRabbitFactory.CreateSingleton();
await client.SubscribeAsync<BasicMessage>(async msg =>
{
  Console.WriteLine($"Received: {msg.Prop}.");
});

await client.PublishAsync(new BasicMessage { Prop = "Hello, world!"});

When i split this code between two or more applications, lets say one app is just publishing messages and others are consuming them it then doesnt work, it requires me to setup bindings between exachanges and queues manually.

For example Using attrbitues My consumer

[Routing(RoutingKey = "event", NoAck = true, PrefetchCount = 50)]
    [Queue(Name = "q")]
    internal class Event
    {
        public DateTime CreatedAt { get; set; }
        public string Message { get; set; }
    }

And producer

[Routing(RoutingKey = "event", NoAck = true, PrefetchCount = 50)]
    [Exchange(Name = "def_q", Type = ExchangeType.Topic)]
    internal class Event
    {
        public DateTime CreatedAt { get; set; }
        public string Message { get; set; }
    }

it still doesnt work with topic exchange, and from my understanding, exchange is the place where i should publish my messages to, then given the routing key it(exchange) should be bound to any queues that accept mentioned routing key, im having trouble understanding why SubscribeAsync<T> creates an exchange for a consumer, shouldnt it create a queue?

am i missing something there?

charconstpointer avatar Aug 19 '19 08:08 charconstpointer

To complement my initial message, all im wondering about is

internal class Event
    {
        public DateTime CreatedAt { get; set; }
        public string Message { get; set; }
    }

why given this model, this call creates an exchange ?

await client.SubscribeAsync<Event>(async message =>
            {
                await Console.Out.WriteLineAsync($"{message.Message}");
            });

and this does not await client.PublishAsync(new Event {CreatedAt = DateTime.UtcNow, Message = "message"});

Shouldnt publisher publish messages to an exchange and consumer listen for those messages on a queue with given routing key?

charconstpointer avatar Aug 19 '19 09:08 charconstpointer

If I'm not mistaken you have the same idiom, Event, placed in separate assemblies as effectively different types. Have you tried with Event put into a common classlib? I see this as something that may affect you.

and this does not

What is the configuration you use? The default has Durable set to true and AutoDelete to false for the exchange.

rpawlaszek avatar Oct 15 '19 22:10 rpawlaszek