Skip to content

Commit 5250316

Browse files
CoenraadSCoenraad Stijne
andauthored
Use user defined loopback address if available ( #374) (#377)
Co-authored-by: Coenraad Stijne <[email protected]>
1 parent df102c4 commit 5250316

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

RabbitMQ.Stream.Client/StreamSystem.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,7 @@ public async Task<StreamInfo> StreamInfo(string streamName)
333333
// when theres 1 endpoint and an address resolver, there could be a cluster behind a load balancer
334334
var forceLocalHost = false;
335335
var localPort = 0;
336+
var localHostOrAddress = "";
336337
if (_clientParameters.Endpoints.Count == 1 &&
337338
_clientParameters.AddressResolver is null)
338339
{
@@ -342,10 +343,12 @@ public async Task<StreamInfo> StreamInfo(string streamName)
342343
case DnsEndPoint { Host: "localhost" } dnsEndPoint:
343344
forceLocalHost = true;
344345
localPort = dnsEndPoint.Port;
346+
localHostOrAddress = dnsEndPoint.Host;
345347
break;
346-
case IPEndPoint ipEndPoint when Equals(ipEndPoint.Address, IPAddress.Loopback):
348+
case IPEndPoint ipEndPoint when IPAddress.IsLoopback(ipEndPoint.Address):
347349
forceLocalHost = true;
348350
localPort = ipEndPoint.Port;
351+
localHostOrAddress = ipEndPoint.Address.ToString();
349352
break;
350353
}
351354
}
@@ -354,7 +357,7 @@ public async Task<StreamInfo> StreamInfo(string streamName)
354357
if (forceLocalHost)
355358
{
356359
// craft the metadata response to force using localhost
357-
var leader = new Broker("localhost", (uint)localPort);
360+
var leader = new Broker(localHostOrAddress, (uint)localPort);
358361
metaStreamInfo = new StreamInfo(streamName, ResponseCode.Ok, leader,
359362
new List<Broker>(1) { leader });
360363
}

0 commit comments

Comments
 (0)