| | |
| | | package com.ruoyi.web; |
| | | |
| | | import com.ruoyi.device.mqtt.DeviceMqttConfig; |
| | | import com.ruoyi.device.mqtt.MQClient; |
| | | import com.ruoyi.device.mqtt.MQConfig; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.eclipse.paho.client.mqttv3.MqttException; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.boot.ApplicationArguments; |
| | | import org.springframework.boot.ApplicationRunner; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import java.util.Objects; |
| | | |
| | | @Component |
| | | @Slf4j |
| | |
| | | @Autowired |
| | | private MQConfig mqConfig; |
| | | |
| | | @Value("${mqtt.client}") |
| | | private Boolean client; |
| | | // @Value("${mqtt.client}") |
| | | // private Boolean client; |
| | | |
| | | @Override |
| | | public void run(ApplicationArguments args) throws Exception { |
| | | if (client) { |
| | | MQClient mqttPushClient = new MQClient(); |
| | | mqttPushClient.connect(mqConfig); |
| | | public void run(ApplicationArguments args) throws MqttException { |
| | | if(Objects.nonNull(mqConfig)){ |
| | | for (DeviceMqttConfig deviceMqttConfig : mqConfig.getMqtt()) { |
| | | if (deviceMqttConfig.getClient()) { |
| | | MQClient mqttPushClient = new MQClient(); |
| | | mqttPushClient.connect(deviceMqttConfig); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |