| | |
| | | |
| | | import com.lunhan.water.common.enums.ELogger; |
| | | import com.lunhan.water.common.util.LoggerUtil; |
| | | import com.lunhan.water.common.util.SpringUtil; |
| | | import com.lunhan.water.common.util.ThreadPoolUtil; |
| | | import com.lunhan.water.service.PaymentRecordsService; |
| | | import org.eclipse.paho.client.mqttv3.IMqttDeliveryToken; |
| | | import org.eclipse.paho.client.mqttv3.MqttCallback; |
| | | import org.eclipse.paho.client.mqttv3.MqttMessage; |
| | | import org.slf4j.Logger; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | |
| | | import java.nio.charset.StandardCharsets; |
| | | import java.util.Objects; |
| | | |
| | | ; |
| | | |
| | |
| | | public class PushCallback implements MqttCallback { |
| | | private static final Logger LOGGER_DEBUG = LoggerUtil.get(ELogger.DEBUG); |
| | | private static final Logger LOGGER_ERROR = LoggerUtil.get(ELogger.SYS_ERROR); |
| | | |
| | | @Autowired |
| | | PaymentRecordsService paymentRecordsService; |
| | | private MQTTSubsribe mqttSubsribe; |
| | | |
| | | public PushCallback(MQTTSubsribe mqttSubsribe) { |
| | |
| | | //这里可以针对收到的消息做处理 |
| | | ThreadPoolUtil.getDefaultPool().execute(() -> { |
| | | try { |
| | | //调用方法 |
| | | //dataUploadYwjRecordService.mqttReceived(topic, msg); |
| | | if (Objects.nonNull(paymentRecordsService)) { |
| | | //调用方法 |
| | | paymentRecordsService.mqttReceived(topic, msg); |
| | | } else { |
| | | try { |
| | | System.out.println("paymentRecordsService bean尚未初始化..."); |
| | | paymentRecordsService = SpringUtil.getBean(PaymentRecordsService.class); |
| | | System.out.println("paymentRecordsService 初始化bean成功!"); |
| | | } catch (Exception ignored) { |
| | | } |
| | | if (Objects.nonNull(paymentRecordsService)) { |
| | | //调用方法 |
| | | paymentRecordsService.mqttReceived(topic, msg); |
| | | } |
| | | } |
| | | } catch (Exception e) { |
| | | LOGGER_ERROR.error("messageArrived", e); |
| | | } |