@@ -46,27 +46,34 @@ int maxAttempts
46
46
{
47
47
var routing = new T ( ) ;
48
48
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
-
57
49
if ( clientParameters . AddressResolver == null
58
50
|| clientParameters . AddressResolver . Enabled == false )
59
51
{
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
+
60
67
// In this case we just return the node (leader for producer, random for consumer)
61
68
// since there is not load balancer configuration
62
69
63
- return routing . CreateClient ( clientParameters with { Endpoint = endPoint } ) ;
70
+ return routing . CreateClient ( clientParameters with { Endpoint = endPointNoLb } ) ;
64
71
}
65
72
66
73
// here it means that there is a AddressResolver configuration
67
74
// so there is a load-balancer or proxy we need to get the right connection
68
75
// as first we try with the first node given from the LB
69
- endPoint = clientParameters . AddressResolver . EndPoint ;
76
+ var endPoint = clientParameters . AddressResolver . EndPoint ;
70
77
var client = routing . CreateClient ( clientParameters with { Endpoint = endPoint } ) ;
71
78
72
79
var advertisedHost = GetPropertyValue ( client . ConnectionProperties , "advertised_host" ) ;
0 commit comments