diff --git a/NewLife.RocketMQ/MqBase.cs b/NewLife.RocketMQ/MqBase.cs index 503aced..ede1f34 100644 --- a/NewLife.RocketMQ/MqBase.cs +++ b/NewLife.RocketMQ/MqBase.cs @@ -68,6 +68,9 @@ public abstract class MqBase : DisposeBase /// public X509Certificate? Certificate { get; set; } + /// 是否使用外部代理。有些RocketMQ的Broker部署在网关外部,需要使用映射地址,默认false + public Boolean ExternalBroker { get; set; } + //public Boolean VipChannelEnabled { get; set; } = true; /// 是否可用 @@ -283,19 +286,22 @@ protected BrokerClient GetBroker(String name) { if (_Brokers.TryGetValue(name, out client)) return client; - // 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++) + if (ExternalBroker) { - var addr = addrs[i]; - if (addr.StartsWithIgnoreCase("10.", "192.", "172.") && !ext.IsNullOrEmpty()) + // broker可能在内网,转为公网地址 + var uri = new NetUri(NameServerAddress.Split(";").FirstOrDefault()); + var ext = uri.Host; + if (ext.IsNullOrEmpty()) ext = uri.Address.ToString(); + + for (var i = 0; i < addrs.Length; i++) { - var p = addr.IndexOf(':'); - addrs[i] = p > 0 ? ext + addr[p..] : ext; + var addr = addrs[i]; + if (addr.StartsWithIgnoreCase("10.", "192.", "172.") && !ext.IsNullOrEmpty()) + { + var p = addr.IndexOf(':'); + addrs[i] = p > 0 ? ext + addr[p..] : ext; + } } }