核心通信模块代码优化、默认日志打印格式修改
This commit is contained in:
parent
338d0f518e
commit
aa1e9fc3a2
@ -111,3 +111,7 @@ management:
|
||||
endpoint:
|
||||
health:
|
||||
show-details: always
|
||||
|
||||
logging:
|
||||
pattern:
|
||||
dateformat: yyyy-MM-dd HH:mm:ss
|
||||
@ -45,8 +45,7 @@ public class MqttConnectionFactory extends BasePooledObjectFactory<Channel> {
|
||||
Channel channel = p.getObject();
|
||||
boolean isValid = channel != null &&
|
||||
channel.isActive()&&
|
||||
channel.isOpen() &&
|
||||
channel.isWritable();
|
||||
channel.isOpen();
|
||||
|
||||
if (!isValid && log.isDebugEnabled()) {
|
||||
log.debug("MQTT连接验证失败");
|
||||
|
||||
@ -4,6 +4,7 @@ import io.netty.buffer.ByteBuf;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.channel.ChannelInboundHandlerAdapter;
|
||||
import io.netty.handler.codec.mqtt.*;
|
||||
import io.netty.handler.timeout.IdleStateEvent;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
@ -14,7 +15,6 @@ import java.nio.charset.StandardCharsets;
|
||||
@Slf4j
|
||||
public class MqttHandler extends ChannelInboundHandlerAdapter {
|
||||
|
||||
private volatile boolean connected = false;
|
||||
@Override
|
||||
public void channelRead(ChannelHandlerContext ctx, Object msg){
|
||||
if (msg instanceof MqttMessage mqttMessage) {
|
||||
@ -130,13 +130,21 @@ public class MqttHandler extends ChannelInboundHandlerAdapter {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void channelInactive(ChannelHandlerContext ctx) throws Exception {
|
||||
if (connected) {
|
||||
log.warn("MQTT连接断开");
|
||||
} else {
|
||||
log.debug("MQTT连接未完成握手即断开");
|
||||
}
|
||||
connected = false;
|
||||
super.channelInactive(ctx);
|
||||
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
|
||||
if (evt instanceof IdleStateEvent idleStateEvent) {
|
||||
switch (idleStateEvent.state()) {
|
||||
case WRITER_IDLE:
|
||||
// 发送PINGREQ心跳
|
||||
MqttMessage pingReq = new MqttMessage(new MqttFixedHeader(
|
||||
MqttMessageType.PINGREQ, false, MqttQoS.AT_MOST_ONCE, false, 0));
|
||||
ctx.writeAndFlush(pingReq);
|
||||
// log.debug("发送PINGREQ心跳");
|
||||
break;
|
||||
case READER_IDLE:
|
||||
// log.warn("读空闲超时,可能连接已断开");
|
||||
break;
|
||||
}
|
||||
}
|
||||
super.userEventTriggered(ctx, evt);
|
||||
}
|
||||
}
|
||||
@ -45,3 +45,7 @@ management:
|
||||
endpoint:
|
||||
health:
|
||||
show-details: always
|
||||
|
||||
logging:
|
||||
pattern:
|
||||
dateformat: yyyy-MM-dd HH:mm:ss
|
||||
@ -110,3 +110,7 @@ minio:
|
||||
secret-key: YuFoH+VJVzQbNLRqVMo39dM5pWXCEcMvrCrtgwB0 # 私有密钥
|
||||
bucket-name: operations-objects
|
||||
show-url: http://47.109.141.125:9000
|
||||
|
||||
logging:
|
||||
pattern:
|
||||
dateformat: yyyy-MM-dd HH:mm:ss
|
||||
|
||||
@ -105,3 +105,7 @@ management:
|
||||
endpoint:
|
||||
health:
|
||||
show-details: always
|
||||
|
||||
logging:
|
||||
pattern:
|
||||
dateformat: yyyy-MM-dd HH:mm:ss
|
||||
@ -56,3 +56,7 @@ management:
|
||||
endpoint:
|
||||
health:
|
||||
show-details: always
|
||||
|
||||
logging:
|
||||
pattern:
|
||||
dateformat: yyyy-MM-dd HH:mm:ss
|
||||
@ -87,4 +87,8 @@ management:
|
||||
health:
|
||||
show-details: always
|
||||
|
||||
logging:
|
||||
pattern:
|
||||
dateformat: yyyy-MM-dd HH:mm:ss
|
||||
|
||||
|
||||
|
||||
@ -105,3 +105,7 @@ minio:
|
||||
bucket-name: user-objects
|
||||
show-url: http://47.109.141.125:9000
|
||||
|
||||
logging:
|
||||
pattern:
|
||||
dateformat: yyyy-MM-dd HH:mm:ss
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user