From 4156bb43c20f3f93fdcd90f1dd58bc1b4247d601 Mon Sep 17 00:00:00 2001 From: zhanxuefeng <18621055368@163.com> Date: Tue, 10 May 2022 17:52:30 +0800 Subject: [PATCH] NettyRemotingClient get tls conf from system properties --- .../storage/dledger/DLedgerRpcNettyService.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/main/java/io/openmessaging/storage/dledger/DLedgerRpcNettyService.java b/src/main/java/io/openmessaging/storage/dledger/DLedgerRpcNettyService.java index 76d35207..2e6d1c7c 100644 --- a/src/main/java/io/openmessaging/storage/dledger/DLedgerRpcNettyService.java +++ b/src/main/java/io/openmessaging/storage/dledger/DLedgerRpcNettyService.java @@ -43,15 +43,20 @@ import java.util.concurrent.Executors; import java.util.concurrent.ThreadFactory; import java.util.concurrent.atomic.AtomicInteger; + +import org.apache.rocketmq.remoting.common.TlsMode; import org.apache.rocketmq.remoting.netty.NettyClientConfig; import org.apache.rocketmq.remoting.netty.NettyRemotingClient; import org.apache.rocketmq.remoting.netty.NettyRemotingServer; import org.apache.rocketmq.remoting.netty.NettyRequestProcessor; import org.apache.rocketmq.remoting.netty.NettyServerConfig; +import org.apache.rocketmq.remoting.netty.TlsSystemConfig; import org.apache.rocketmq.remoting.protocol.RemotingCommand; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import static org.apache.rocketmq.remoting.netty.TlsSystemConfig.TLS_ENABLE; + /** * A netty implementation of DLedgerRpcService. It should be bi-directional, which means it implements both * DLedgerProtocol and DLedgerProtocolHandler. @@ -123,7 +128,10 @@ public boolean rejectRequest() { this.remotingServer.registerProcessor(DLedgerRequestCode.LEADERSHIP_TRANSFER.getCode(), protocolProcessor, null); //start the remoting client - this.remotingClient = new NettyRemotingClient(new NettyClientConfig(), null); + NettyClientConfig nettyClientConfig = new NettyClientConfig(); + nettyClientConfig.setUseTLS(Boolean.parseBoolean(System.getProperty(TLS_ENABLE, + String.valueOf(TlsSystemConfig.tlsMode == TlsMode.ENFORCING)))); + this.remotingClient = new NettyRemotingClient(nettyClientConfig, null); }