Skip to content

Commit

Permalink
✨ 简化代码
Browse files Browse the repository at this point in the history
  • Loading branch information
ChunMengLu committed Mar 23, 2024
1 parent 41854e5 commit db8b49f
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ mqtt:
keep-alive-secs: 60 # keep-alive 时间,单位:秒
clean-session: true # mqtt clean session,默认:true
will-message:

topic: /test/offline
message: down
ssl:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import org.tio.client.TioClient;
import org.tio.client.TioClientConfig;

import java.util.ArrayList;
import java.util.List;

/**
Expand All @@ -39,7 +38,6 @@ public class MqttClientTemplate implements SmartInitializingSingleton, Disposabl
private final ObjectProvider<IMqttClientConnectListener> clientConnectListenerObjectProvider;
private final ObjectProvider<IMqttClientGlobalMessageListener> globalMessageListenerObjectProvider;
private final ObjectProvider<MqttClientCustomizer> customizersObjectProvider;
private final List<MqttClientSubscription> tempSubscriptionList;
private MqttClient client;

public MqttClientTemplate(MqttClientCreator clientCreator,
Expand All @@ -55,7 +53,6 @@ public MqttClientTemplate(MqttClientCreator clientCreator,
this.clientConnectListenerObjectProvider = clientConnectListenerObjectProvider;
this.globalMessageListenerObjectProvider = globalMessageListenerObjectProvider;
this.customizersObjectProvider = customizersObjectProvider;
this.tempSubscriptionList = new ArrayList<>();
}

/**
Expand Down Expand Up @@ -271,19 +268,6 @@ public MqttClient getMqttClient() {
return client;
}

/**
* 添加启动时的临时订阅
*
* @param topicFilters topicFilters
* @param qos MqttQoS
* @param messageListener IMqttClientMessageListener
*/
void addSubscriptionList(String[] topicFilters, MqttQoS qos, IMqttClientMessageListener messageListener) {
for (String topicFilter : topicFilters) {
tempSubscriptionList.add(new MqttClientSubscription(qos, topicFilter, messageListener));
}
}

@Override
public void afterSingletonsInstantiated() {
// 配置客户端连接监听器
Expand All @@ -303,9 +287,6 @@ public void afterSingletonsInstantiated() {
}
// 使用同步连接,不过如果连不上会卡一会
client = clientCreator.connectSync();
// 添加订阅并清理零时订阅存储
client.subscribe(tempSubscriptionList);
tempSubscriptionList.clear();
}

@Override
Expand Down

0 comments on commit db8b49f

Please sign in to comment.