Commit 3bbed3f
committed
Prefer replicas over leader for consumer connections
The Go client currently uses equal probability distribution for consumer
placement, including the leader node in the candidate pool alongside
replicas. This results in consumers connecting to the leader ~33% of the
time (with 2 replicas), which violates RabbitMQ Streams best practices
that recommend consumers connect to replicas rather than leaders.
This change modifies `BrokerForConsumerWithResolver` to only include the
leader in the candidate pool when no replicas are available. When replicas
exist, consumers randomly select from replicas only, guaranteeing zero
probability of leader placement. This matches the .NET client behavior and
follows RabbitMQ Streams best practices for consumer placement.
The leader is used as a fallback when `availableReplicas == 0`, ensuring
consumers can still connect when replicas are unavailable.1 parent b8578b7 commit 3bbed3f
2 files changed
+54
-2
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
677 | 677 | | |
678 | 678 | | |
679 | 679 | | |
| 680 | + | |
| 681 | + | |
| 682 | + | |
| 683 | + | |
680 | 684 | | |
681 | 685 | | |
682 | 686 | | |
| |||
693 | 697 | | |
694 | 698 | | |
695 | 699 | | |
| 700 | + | |
| 701 | + | |
| 702 | + | |
| 703 | + | |
| 704 | + | |
| 705 | + | |
| 706 | + | |
696 | 707 | | |
697 | 708 | | |
698 | 709 | | |
| |||
738 | 749 | | |
739 | 750 | | |
740 | 751 | | |
741 | | - | |
| 752 | + | |
| 753 | + | |
| 754 | + | |
| 755 | + | |
| 756 | + | |
| 757 | + | |
| 758 | + | |
| 759 | + | |
| 760 | + | |
| 761 | + | |
| 762 | + | |
| 763 | + | |
| 764 | + | |
| 765 | + | |
| 766 | + | |
| 767 | + | |
| 768 | + | |
742 | 769 | | |
743 | 770 | | |
744 | 771 | | |
745 | 772 | | |
746 | 773 | | |
| 774 | + | |
| 775 | + | |
747 | 776 | | |
748 | 777 | | |
749 | 778 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
619 | 619 | | |
620 | 620 | | |
621 | 621 | | |
| 622 | + | |
| 623 | + | |
| 624 | + | |
| 625 | + | |
| 626 | + | |
| 627 | + | |
| 628 | + | |
| 629 | + | |
| 630 | + | |
| 631 | + | |
| 632 | + | |
| 633 | + | |
| 634 | + | |
| 635 | + | |
| 636 | + | |
| 637 | + | |
622 | 638 | | |
623 | 639 | | |
624 | 640 | | |
625 | 641 | | |
626 | 642 | | |
627 | 643 | | |
628 | 644 | | |
| 645 | + | |
| 646 | + | |
| 647 | + | |
| 648 | + | |
| 649 | + | |
| 650 | + | |
| 651 | + | |
629 | 652 | | |
630 | 653 | | |
631 | 654 | | |
| |||
664 | 687 | | |
665 | 688 | | |
666 | 689 | | |
667 | | - | |
| 690 | + | |
668 | 691 | | |
669 | 692 | | |
670 | 693 | | |
| |||
0 commit comments