Skip to content

Commit

Permalink
Use user defined loopback address if available ( #374) (#377)
Browse files Browse the repository at this point in the history
Co-authored-by: Coenraad Stijne <coenraad.stijne@innerrange.com>
  • Loading branch information
CoenraadS and Coenraad Stijne authored May 21, 2024
1 parent df102c4 commit 5250316
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions RabbitMQ.Stream.Client/StreamSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,7 @@ public async Task<StreamInfo> StreamInfo(string streamName)
// when theres 1 endpoint and an address resolver, there could be a cluster behind a load balancer
var forceLocalHost = false;
var localPort = 0;
var localHostOrAddress = "";
if (_clientParameters.Endpoints.Count == 1 &&
_clientParameters.AddressResolver is null)
{
Expand All @@ -342,10 +343,12 @@ public async Task<StreamInfo> StreamInfo(string streamName)
case DnsEndPoint { Host: "localhost" } dnsEndPoint:
forceLocalHost = true;
localPort = dnsEndPoint.Port;
localHostOrAddress = dnsEndPoint.Host;
break;
case IPEndPoint ipEndPoint when Equals(ipEndPoint.Address, IPAddress.Loopback):
case IPEndPoint ipEndPoint when IPAddress.IsLoopback(ipEndPoint.Address):
forceLocalHost = true;
localPort = ipEndPoint.Port;
localHostOrAddress = ipEndPoint.Address.ToString();
break;
}
}
Expand All @@ -354,7 +357,7 @@ public async Task<StreamInfo> StreamInfo(string streamName)
if (forceLocalHost)
{
// craft the metadata response to force using localhost
var leader = new Broker("localhost", (uint)localPort);
var leader = new Broker(localHostOrAddress, (uint)localPort);
metaStreamInfo = new StreamInfo(streamName, ResponseCode.Ok, leader,
new List<Broker>(1) { leader });
}
Expand Down

0 comments on commit 5250316

Please sign in to comment.