@@ -46,27 +46,34 @@ int maxAttempts
4646 {
4747 var routing = new T ( ) ;
4848
49- var endPoint = new IPEndPoint ( IPAddress . Loopback , ( int ) broker . Port ) ;
50-
51- if ( routing . ValidateDns )
52- {
53- var hostEntry = await Dns . GetHostEntryAsync ( broker . Host ) ;
54- endPoint = new IPEndPoint ( hostEntry . AddressList . First ( ) , ( int ) broker . Port ) ;
55- }
56-
5749 if ( clientParameters . AddressResolver == null
5850 || clientParameters . AddressResolver . Enabled == false )
5951 {
52+ // We use the localhost ip as default
53+ // this is mostly to have a default value.
54+
55+ var endPointNoLb = new IPEndPoint ( IPAddress . Loopback , ( int ) broker . Port ) ;
56+
57+ // ValidateDns just validate the DNS
58+ // it the real world application is always TRUE
59+ // routing.ValidateDns == false is used just for test
60+ // it should not change.
61+ if ( routing . ValidateDns )
62+ {
63+ var hostEntry = await Dns . GetHostEntryAsync ( broker . Host ) ;
64+ endPointNoLb = new IPEndPoint ( hostEntry . AddressList . First ( ) , ( int ) broker . Port ) ;
65+ }
66+
6067 // In this case we just return the node (leader for producer, random for consumer)
6168 // since there is not load balancer configuration
6269
63- return routing . CreateClient ( clientParameters with { Endpoint = endPoint } ) ;
70+ return routing . CreateClient ( clientParameters with { Endpoint = endPointNoLb } ) ;
6471 }
6572
6673 // here it means that there is a AddressResolver configuration
6774 // so there is a load-balancer or proxy we need to get the right connection
6875 // as first we try with the first node given from the LB
69- endPoint = clientParameters . AddressResolver . EndPoint ;
76+ var endPoint = clientParameters . AddressResolver . EndPoint ;
7077 var client = routing . CreateClient ( clientParameters with { Endpoint = endPoint } ) ;
7178
7279 var advertisedHost = GetPropertyValue ( client . ConnectionProperties , "advertised_host" ) ;
0 commit comments