Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Confused about binding between exchange and queues #403

Open
charconstpointer opened this issue Aug 19, 2019 · 2 comments
Open

Confused about binding between exchange and queues #403

charconstpointer opened this issue Aug 19, 2019 · 2 comments

Comments

@charconstpointer
Copy link

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 creates an exchange for a consumer, shouldnt it create a queue?

am i missing something there?

@charconstpointer charconstpointer changed the title Consumer creating Confused about binding between exchange and queues Aug 19, 2019
@charconstpointer
Copy link
Author

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?

@rpawlaszek
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants