diff --git a/xymanager_admin/src/main/resources/application-test.yml b/xymanager_admin/src/main/resources/application-test.yml index 2b95c6c..25e310c 100644 --- a/xymanager_admin/src/main/resources/application-test.yml +++ b/xymanager_admin/src/main/resources/application-test.yml @@ -127,13 +127,11 @@ rsa: private_key: MIICdwIBADANBgkqhkiG9w0BAQEFAASCAmEwggJdAgEAAoGBAJWKrQv7VcJMo6S32ebL1pBsxE00k0E609hGUKr9tG7CVhqr8j5epIOQgXyzgklLLf9WCPDR+nx3g77koFLg6b0SVrrQjZW/+rwuMI0U1htETrEjvKuXI+6Sh2YL+zVWA4MNEefe9XIpwr2fIXvFmxeLGeW+W0CTLzzwImQumIaNAgMBAAECgYAzOn2LlD9Nv5lzzTPNl9jaQxiAZllnyDJYbcYmvaD5LIP4wRzMdvmexHtHb+tbFnEcfqmzbguEZiDw3Tt7COepQWvNzlM+/HbFtkXzSh6WEu2TgjZwudcCDHDyjDzUNgcWnBIw8/+Sy4COOm4p+UnprYK4sdriMZyz8K5UC8CxFQJBAODTt0lg/HiZKaOX7PMmsiRisd5oAslyDHCt66oPG29KTE1j4fwKDzGJlrOo1f4Q078IDYMO1I/Y3uP8Es3FT1MCQQCqRrD+lO3YCZOUGTHm2WGmbljIoeDpnIn2TZFyqDGKXs6EAx7SXkgarY2OC5O2aifMhXElPUGChfSgPmRUFHafAkEAxFtkWuwf1NxAJ6cKxZpoP6sLGenRdUrsXoUnrBEhruM/HOA9gLjwaB14x1SQASOFK/TGiE4ti6ynjoqbiafoDQJBAI0l6FZAsiBhX9pmQD1yeUXzNtmphr1gK+TmS+lVjyt6h4pa49PSn8atkyfqZNnTiYY6H56U9pbx3+Rtk9E23VUCQEZ9/JHUaGc77s3ibpcKFVemlb0i/Uvj2V45aoNfY34iex4biAUsRq/FJNiqBk+xQWkJ4QY8nKVE45GlaCfZ8/c= mqtt: - clientId: xymp_client + enable: false + clientId: code_client broker: tcp://61.169.135.146:51001 username: xymp password: xymp - cmdtopic: /v1/devices/MSRDT-A/command - resptopic: /v1/devices/MSRDT-A/commandResponse - datatopic: /v1/devices/MSRDT-A/datas photodir: /home/xymp/photos/ camera-schedule: false \ No newline at end of file diff --git a/xymanager_framework/src/main/java/com/shxy/xymanager_framework/config/MqttConfig.java b/xymanager_framework/src/main/java/com/shxy/xymanager_framework/config/MqttConfig.java index 228c467..dcdf6da 100644 --- a/xymanager_framework/src/main/java/com/shxy/xymanager_framework/config/MqttConfig.java +++ b/xymanager_framework/src/main/java/com/shxy/xymanager_framework/config/MqttConfig.java @@ -10,6 +10,9 @@ import org.springframework.context.annotation.Configuration; @Configuration public class MqttConfig { + @Value("${mqtt.enable:false}") + private boolean enable; + @Value("${mqtt.broker}") private String broker; @@ -35,6 +38,9 @@ public class MqttConfig { @Bean public MqttClient mqttClient(MqttConnectOptions options) throws MqttException { + if (!enable) { + return null; + } MqttClient client = new MqttClient(broker, clientId); client.connect(options); return client; diff --git a/xymanager_service/src/main/java/com/shxy/xymanager_service/mqtt/MqttSubscriberService.java b/xymanager_service/src/main/java/com/shxy/xymanager_service/mqtt/MqttSubscriberService.java index 96ac06a..8a925f8 100644 --- a/xymanager_service/src/main/java/com/shxy/xymanager_service/mqtt/MqttSubscriberService.java +++ b/xymanager_service/src/main/java/com/shxy/xymanager_service/mqtt/MqttSubscriberService.java @@ -5,6 +5,7 @@ import com.shxy.xymanager_service.service.NewCacheService; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; import org.eclipse.paho.client.mqttv3.MqttClient; +import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import javax.annotation.PostConstruct; @@ -20,6 +21,9 @@ import static com.shxy.xymanager_common.constant.Constants.*; @Slf4j public class MqttSubscriberService { + @Value("${mqtt.enable:false}") + private boolean enable; + @Resource private MqttClient mqttClient; @Resource @@ -31,6 +35,9 @@ public class MqttSubscriberService { @PostConstruct public void init() throws Exception { + if (!enable) { + return; + } List modelList = new ArrayList<>(); Map terminalMap = newCacheService.getTerminalMap(); Iterator it = terminalMap.keySet().iterator();