RawRabbit
RawRabbit copied to clipboard
Confused about binding between exchange and queues
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?
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?
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.