4
votes

In trying to understanding the difference between direct, fanout and topic exchanges, I want to confirm that the advantage of a topic exchange is that a producer pushes to an exchange and specifies a fully specific routing key, and queues can bind to multiple routing keys via wildcards. e.g. topic pushes to...

$channel->basic_publish($msg, 'logs-exchange', 'error.critical.ram')

And a queue that would message the on-call team on all critical errors would bind like...

$channel->queue_bind('on-call-team', 'logs-exchange', 'error.critical.*')

And a similar queue with error.*.ram would message the sysops team responsible for increasing ram.

Is this the correct use case for a topic exchange, and is the topic exchange the only exchange that can support this flexibility? Conversely are both topic and fanout exchanges implementable by a topic exchange?

1

1 Answers

3
votes

Is this the correct use case for a topic exchange,

Yes absolutely correct usage for this exchange. You will see that it is very powerful

and is the topic exchange the only exchange that can support this flexibility?

Yes, the direct exchange which is similar will not support wildcards so you have to specify the full routing key when you bind to it otherwise it will not receive messages. There maybe custom messages that use topic exchanges as basis but I cannot think of one off hand

Conversely are both topic and fanout exchanges implementable by a topic exchange?

I am not sure what you mean here. Yes you could have mutiple queue's bind to the exchange with the same binding key, so they will all receive the same messages. But if you do not need that functionality then you might as well use the fanout exchange itself.

Additionally I have a fanout exchange that is bound to some queues and a topic exchange. The publisher to this exchange uses a routing key, even though it is not needed for the fanout exchange it is needed for the topic exchange that it gets routed to. This is good because it has no effect on the fanout with our causing problems for the topic exchanges