在mqtt客户端订阅topic的时候,使用IMqttMessageListener监听特定的topic,监听器代码如下:
public class DelayedMessageListener implements IMqttMessageListener {
@Autowired
private ApiConfig apiConfig;
@Override
public void messageArrived(String topic, MqttMessage message) {
String resultCode = HttpPoolManager.sendPostRequest(apiConfig.getMeetingController().getDelayedMessage(), new String(message.getPayload()));
log.info(“延迟消息推送结果:{}”, resultCode);
}
}
订阅操作代码如下:
mqttClient.subscribe(“$share/device_links/SYSTEM/delayed_message”,
bizData.getQos(), delayedMessageListener);
mqttDelayedMessage.setTopic(mqttClientTopic);
随后往SYSTEM/delayed_message中发送消息,发现消息并不会被delayedMessageListener监听,而是直接被callback捕获。在dashboard中查看当前客户端的订阅情况:
发现订阅并没有问题,是不是IMqttMessageListener 并不能处理共享订阅的topic?