From 93cbb185fcea04dcb94e1a5bb84e55abd4e21e2c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=A7=E7=9F=B3=E5=A4=B4?= Date: Tue, 10 Dec 2024 17:08:48 +0800 Subject: [PATCH] =?UTF-8?q?[feat]=20=E6=96=B0=E5=A2=9E=20ExternalBroker=20?= =?UTF-8?q?=E6=98=AF=E5=90=A6=E4=BD=BF=E7=94=A8=E5=A4=96=E9=83=A8=E4=BB=A3?= =?UTF-8?q?=E7=90=86=E3=80=82=E6=9C=89=E4=BA=9BRocketMQ=E7=9A=84Broker?= =?UTF-8?q?=E9=83=A8=E7=BD=B2=E5=9C=A8=E7=BD=91=E5=85=B3=E5=A4=96=E9=83=A8?= =?UTF-8?q?=EF=BC=8C=E9=9C=80=E8=A6=81=E4=BD=BF=E7=94=A8=E6=98=A0=E5=B0=84?= =?UTF-8?q?=E5=9C=B0=E5=9D=80=EF=BC=8C=E9=BB=98=E8=AE=A4false=20=E3=80=82h?= =?UTF-8?q?ttps://github.com/NewLifeX/NewLife.RocketMQ/issues/85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- NewLife.RocketMQ/MqBase.cs | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) 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; + } } }