From 52503165a81216b844ce81e2adbd96568be2035b Mon Sep 17 00:00:00 2001 From: CoenraadS Date: Tue, 21 May 2024 22:24:45 +1000 Subject: [PATCH] Use user defined loopback address if available ( #374) (#377) Co-authored-by: Coenraad Stijne --- RabbitMQ.Stream.Client/StreamSystem.cs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/RabbitMQ.Stream.Client/StreamSystem.cs b/RabbitMQ.Stream.Client/StreamSystem.cs index ffabd762..d6156558 100644 --- a/RabbitMQ.Stream.Client/StreamSystem.cs +++ b/RabbitMQ.Stream.Client/StreamSystem.cs @@ -333,6 +333,7 @@ public async Task 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) { @@ -342,10 +343,12 @@ public async Task 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; } } @@ -354,7 +357,7 @@ public async Task 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(1) { leader }); }