支持指定重连间隔、是否无限重连
This commit is contained in:
+7
@@ -41,5 +41,12 @@ public class ProxyConfig {
|
||||
private Integer threadCount;
|
||||
private String clientId;
|
||||
private Boolean transferLogEnable;
|
||||
private Reconnection reconnection;
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class Reconnection {
|
||||
private Integer intervalSeconds;
|
||||
private Boolean unlimited;
|
||||
}
|
||||
}
|
||||
|
||||
+5
-5
@@ -49,10 +49,10 @@ public class ProxyClientService {
|
||||
@Inject("realServerBootstrap")
|
||||
private Bootstrap realServerBootstrap;
|
||||
private volatile Channel channel;
|
||||
/**
|
||||
* 重连间隔(秒)
|
||||
*/
|
||||
private static final long RECONNECT_INTERVAL_SECONDS = 5;
|
||||
// /**
|
||||
// * 重连间隔(秒)
|
||||
// */
|
||||
// private static final long RECONNECT_INTERVAL_SECONDS = 5;
|
||||
/**
|
||||
* 重连次数
|
||||
*/
|
||||
@@ -69,7 +69,7 @@ public class ProxyClientService {
|
||||
|
||||
@Init
|
||||
public void init() {
|
||||
this.reconnectExecutor.scheduleWithFixedDelay(this::reconnect, 10, RECONNECT_INTERVAL_SECONDS, TimeUnit.SECONDS);
|
||||
this.reconnectExecutor.scheduleWithFixedDelay(this::reconnect, 10, proxyConfig.getClient().getReconnection().getIntervalSeconds(), TimeUnit.SECONDS);
|
||||
this.workerGroup = new NioEventLoopGroup(proxyConfig.getClient().getThreadCount());
|
||||
|
||||
realServerBootstrap.group(workerGroup);
|
||||
|
||||
+7
-1
@@ -1,6 +1,7 @@
|
||||
package org.dromara.neutrinoproxy.client.handler;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import org.dromara.neutrinoproxy.client.config.ProxyConfig;
|
||||
import org.dromara.neutrinoproxy.core.Constants;
|
||||
import org.dromara.neutrinoproxy.core.ExceptionEnum;
|
||||
import org.dromara.neutrinoproxy.core.ProxyMessage;
|
||||
@@ -10,6 +11,7 @@ import io.netty.channel.ChannelHandlerContext;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.noear.solon.Solon;
|
||||
import org.noear.solon.annotation.Component;
|
||||
import org.noear.solon.annotation.Inject;
|
||||
|
||||
/**
|
||||
* 认证信息处理器
|
||||
@@ -20,6 +22,8 @@ import org.noear.solon.annotation.Component;
|
||||
@Match(type = Constants.ProxyDataTypeName.AUTH)
|
||||
@Component
|
||||
public class ProxyMessageAuthHandler implements ProxyMessageHandler {
|
||||
@Inject
|
||||
private ProxyConfig proxyConfig;
|
||||
@Override
|
||||
public void handle(ChannelHandlerContext context, ProxyMessage proxyMessage) {
|
||||
String info = proxyMessage.getInfo();
|
||||
@@ -30,7 +34,9 @@ public class ProxyMessageAuthHandler implements ProxyMessageHandler {
|
||||
// 客户端认证失败,直接停止服务
|
||||
log.info("client auth failed , client stop.");
|
||||
context.channel().close();
|
||||
Solon.stop();
|
||||
if (!proxyConfig.getClient().getReconnection().getUnlimited()) {
|
||||
Solon.stop();
|
||||
}
|
||||
} else if (ExceptionEnum.CONNECT_FAILED.getCode().equals(code) ||
|
||||
ExceptionEnum.LICENSE_CANNOT_REPEAT_CONNECT.getCode().equals(code)
|
||||
){
|
||||
|
||||
@@ -4,7 +4,7 @@ neutrino:
|
||||
|
||||
proxy:
|
||||
logger:
|
||||
level: info
|
||||
level: ${LOG_LEVEL:info}
|
||||
protocol:
|
||||
max-frame-length: 2097152
|
||||
length-field-offset: 0
|
||||
@@ -25,3 +25,6 @@ neutrino:
|
||||
license-key: ${LICENSE_KEY:}
|
||||
client-id: ${CLIENT_ID:}
|
||||
transfer-log-enable: ${CLIENT_LOG:false}
|
||||
reconnection:
|
||||
interval-seconds: 10
|
||||
unlimited: false
|
||||
|
||||
@@ -4,7 +4,7 @@ server:
|
||||
neutrino:
|
||||
proxy:
|
||||
logger:
|
||||
level: info
|
||||
level: ${LOG_LEVEL:info}
|
||||
protocol:
|
||||
max-frame-length: ${MAX_FRAME_LENGTH:2097152}
|
||||
length-field-offset: 0
|
||||
|
||||
Reference in New Issue
Block a user