Skip to content

Commit

Permalink
[fix] NameServerAddress地址可能没有使用域名,而是使用IP。fix: #85
Browse files Browse the repository at this point in the history
  • Loading branch information
nnhy committed Dec 10, 2024
1 parent 40fe924 commit ae97b0d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
7 changes: 5 additions & 2 deletions NewLife.RocketMQ/MqBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -285,14 +285,17 @@ protected BrokerClient GetBroker(String name)

// broker可能在内网,转为公网地址
var uri = new NetUri(NameServerAddress.Split(";").FirstOrDefault());
var ext = uri.Host;
if (ext.IsNullOrEmpty()) ext = uri.Address.ToString();

var addrs = bk.Addresses.ToArray();
for (var i = 0; i < addrs.Length; i++)
{
var addr = addrs[i];
if (addr.StartsWithIgnoreCase("10.", "192.", "172."))
if (addr.StartsWithIgnoreCase("10.", "192.", "172.") && !ext.IsNullOrEmpty())
{
var p = addr.IndexOf(':');
addrs[i] = p > 0 ? uri.Host + addr[p..] : uri.Host;
addrs[i] = p > 0 ? ext + addr[p..] : ext;
}
}

Expand Down
2 changes: 1 addition & 1 deletion NewLife.RocketMQ/NewLife.RocketMQ.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="NewLife.Core" Version="11.0.2024.1201" />
<PackageReference Include="NewLife.Core" Version="11.1.2024.1206" />
</ItemGroup>

</Project>

0 comments on commit ae97b0d

Please sign in to comment.