mqtt连接池优化、去除多于依赖
This commit is contained in:
parent
65996f5be5
commit
2253508efb
@ -44,6 +44,9 @@ public class MqttConnectionPool implements DisposableBean, InitializingBean {
|
|||||||
config.setMaxTotal(MqttConfig.getPoolMaxTotal());
|
config.setMaxTotal(MqttConfig.getPoolMaxTotal());
|
||||||
config.setMaxIdle(MqttConfig.getPoolMaxIdle());
|
config.setMaxIdle(MqttConfig.getPoolMaxIdle());
|
||||||
config.setMinIdle(MqttConfig.getPoolMinIdle());
|
config.setMinIdle(MqttConfig.getPoolMinIdle());
|
||||||
|
|
||||||
|
config.setBlockWhenExhausted(true); // 必须设置为 true
|
||||||
|
config.setMaxWaitMillis(5000); // 等待5秒,不能无限等待
|
||||||
|
|
||||||
// 启用空闲连接维护
|
// 启用空闲连接维护
|
||||||
config.setTimeBetweenEvictionRuns(Duration.ofMinutes(5));
|
config.setTimeBetweenEvictionRuns(Duration.ofMinutes(5));
|
||||||
@ -53,7 +56,7 @@ public class MqttConnectionPool implements DisposableBean, InitializingBean {
|
|||||||
|
|
||||||
config.setTestOnBorrow(false);
|
config.setTestOnBorrow(false);
|
||||||
config.setTestOnReturn(false);
|
config.setTestOnReturn(false);
|
||||||
config.setTestOnReturn(false);
|
config.setTestWhileIdle(true); // 空闲时验证(保持连接健康)
|
||||||
|
|
||||||
connectionPool = new GenericObjectPool<>(mqttConnectionFactory, config);
|
connectionPool = new GenericObjectPool<>(mqttConnectionFactory, config);
|
||||||
|
|
||||||
|
|||||||
@ -38,6 +38,7 @@ public class MqttHandler extends ChannelInboundHandlerAdapter {
|
|||||||
case CONNACK:
|
case CONNACK:
|
||||||
// CONNACK已经在专门的handler中处理,这里不应该收到
|
// CONNACK已经在专门的handler中处理,这里不应该收到
|
||||||
log.warn("在MqttHandler中收到CONNACK,可能配置有误");
|
log.warn("在MqttHandler中收到CONNACK,可能配置有误");
|
||||||
|
handleConnAck(ctx,(MqttConnAckMessage)mqttMessage);
|
||||||
break;
|
break;
|
||||||
case PUBLISH:
|
case PUBLISH:
|
||||||
handlePublish(ctx, (MqttPublishMessage) mqttMessage);
|
handlePublish(ctx, (MqttPublishMessage) mqttMessage);
|
||||||
@ -46,7 +47,7 @@ public class MqttHandler extends ChannelInboundHandlerAdapter {
|
|||||||
handlePubAck((MqttPubAckMessage) mqttMessage);
|
handlePubAck((MqttPubAckMessage) mqttMessage);
|
||||||
break;
|
break;
|
||||||
case PINGRESP:
|
case PINGRESP:
|
||||||
log.debug("收到PING响应");
|
// log.debug("收到PING响应");
|
||||||
break;
|
break;
|
||||||
case SUBACK:
|
case SUBACK:
|
||||||
handleSubAck((MqttSubAckMessage) mqttMessage);
|
handleSubAck((MqttSubAckMessage) mqttMessage);
|
||||||
|
|||||||
9
pom.xml
9
pom.xml
@ -35,7 +35,6 @@
|
|||||||
<mybatis-flex.version>1.11.3</mybatis-flex.version>
|
<mybatis-flex.version>1.11.3</mybatis-flex.version>
|
||||||
<mybatis.version>3.0.4</mybatis.version>
|
<mybatis.version>3.0.4</mybatis.version>
|
||||||
<satoken.version>1.40.0</satoken.version>
|
<satoken.version>1.40.0</satoken.version>
|
||||||
<mysql.version>8.0.32</mysql.version>
|
|
||||||
<HikariCP.version>5.0.1</HikariCP.version>
|
<HikariCP.version>5.0.1</HikariCP.version>
|
||||||
<okhttp.version>4.12.0</okhttp.version>
|
<okhttp.version>4.12.0</okhttp.version>
|
||||||
<minio.version>8.5.7</minio.version>
|
<minio.version>8.5.7</minio.version>
|
||||||
@ -177,14 +176,6 @@
|
|||||||
<scope>import</scope>
|
<scope>import</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.mysql</groupId>
|
|
||||||
<artifactId>mysql-connector-j</artifactId>
|
|
||||||
<version>${mysql.version}</version>
|
|
||||||
<type>pom</type>
|
|
||||||
<scope>import</scope>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.data</groupId>
|
<groupId>org.springframework.data</groupId>
|
||||||
<artifactId>spring-data-bom</artifactId>
|
<artifactId>spring-data-bom</artifactId>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user