aix
2024-08-14 5d06d78cbf238c383a229f61bf16d3c59051ee9e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package com.dji.sample.component.mqtt.service.impl;
 
import com.dji.sample.component.mqtt.service.IMqttTopicService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.integration.mqtt.inbound.MqttPahoMessageDrivenChannelAdapter;
import org.springframework.stereotype.Component;
 
import javax.annotation.Resource;
 
/**
 *
 * @author sean.zhou
 * @date 2021/11/10
 * @version 0.1
 */
@Component
@Slf4j
public class MqttTopicServiceImpl implements IMqttTopicService {
 
    @Resource
    private MqttPahoMessageDrivenChannelAdapter adapter;
 
    @Override
    public void subscribe(String topic) {
        log.debug("subscribe topic: {}", topic);
        adapter.addTopic(topic);
    }
 
    @Override
    public void subscribe(String topic, int qos) {
        log.debug("subscribe topic: {}", topic);
        adapter.addTopic(topic, qos);
    }
 
    @Override
    public void unsubscribe(String topic) {
        log.debug("unsubscribe topic: {}", topic);
        adapter.removeTopic(topic);
    }
 
    public String[] getSubscribedTopic() {
        return adapter.getTopic();
    }
}