Hi,
Let me start by reminding you that you should not be using classic mirrored queues.
They were already removed from the main branch and won't be available at all in the next version.
Having said that, as you pointed out, the question applies to all queue types, including streams.
You also know the answer already: yes, for the best performance it's better to be connected to the leader,
at least for publishing. The consumption is not so obvious because quorum queues and streams
support consumption from a follower and therefore spreading consumers across the cluster will
generally yield better results (more uniform distribution of load across the nodes + the leaders
have more resources available to handle the publishers, since publishing has to go through the leader).
So why don't we just always connect to the leader for publishing? Consider just two scenarios:
* a publisher publishes to a fanout exchange, which routes messages to many queues, which can be on different nodes.
Which node should the publisher be connected to in this case?
* an even simpler scenario - a publisher publishes to a direct exchange with 1 binding per key, so we could check where that
one queue is, but what if the next message is published with a different routing key and therefore routed to a different
queue, which happens to be on a different node? Should we keep telling the publisher to reconnect to a different
node? That would be much worse than what we do right now.
It's not an easy problem to solve. Moreover, the publishing latency is not that critical for many use cases - after all
if you are using a queueing system, you accept the fact that a message can be queued, right? So the fact that it may
take a bit longer to reach the queue in the first place, should not be such a big deal. We discussed some ideas in the
past and some may materialize in the future. For cases where you know which queue the publisher should be collocated
with, we could have some way for the publisher to express that wish, and for RabbitMQ to fulfill it, if possible.
But for more users, the simplicity and flexibility of the current approach (just connect to one of the nodes and everything
will work) is much more important than the lowest possible latency.
In cases that require low latency, you can design your system with the publisher/consumer locality in mind
and/or use a single node. Additionally, in RabbitMQ 4.0, we will introduce a new exchange type,
It depends on your applications being deployed in a certain way (see the docs), but that's just
the reality of distributed systems and optimising for low latency: there's no magic bullet/toggle to just
"enable low latency".
Best,