Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 21 additions & 3 deletions RabbitMQ.Stream.Client/RoutingClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,15 @@ private static async Task<IClient> LookupConnection(
// We use the localhost ip as default
// this is mostly to have a default value.

var endPointNoLb = new IPEndPoint(IPAddress.Loopback, (int)broker.Port);
EndPoint endPointNoLb = new IPEndPoint(IPAddress.Loopback, (int)broker.Port);

// ValidateDns just validate the DNS
// it the real world application is always TRUE
// routing.ValidateDns == false is used just for test
// it should not change.
if (routing.ValidateDns)
{
var hostEntry = await Dns.GetHostEntryAsync(broker.Host);
endPointNoLb = new IPEndPoint(hostEntry.AddressList.First(), (int)broker.Port);
endPointNoLb = await GetEndPoint(broker);
}

// In this case we just return the node (leader for producer, random for consumer)
Expand Down Expand Up @@ -100,6 +99,25 @@ private static async Task<IClient> LookupConnection(
return client;
}

internal static async Task<EndPoint> GetEndPoint(Broker broker)
{
switch (Uri.CheckHostName(broker.Host))
{
case UriHostNameType.Basic:
case UriHostNameType.Dns:
var hostEntry = await Dns.GetHostEntryAsync(broker.Host);
var endPointNoLb = new IPEndPoint(hostEntry.AddressList.First(), (int)broker.Port);
return endPointNoLb;
case UriHostNameType.IPv4:
case UriHostNameType.IPv6:
return new IPEndPoint(IPAddress.Parse(broker.Host), (int)broker.Port);
case UriHostNameType.Unknown:
throw new RoutingClientException($"Unknown host name {broker.Host}");
default:
throw new RoutingClientException($"Unknown host name {broker.Host}");
}
}

private static int MaxAttempts(StreamInfo metaDataInfo)
{
// Here we have a reasonable number of retry.
Expand Down