aix
2024-08-14 5d06d78cbf238c383a229f61bf16d3c59051ee9e
src/main/java/com/dji/sample/component/mqtt/service/impl/MessageSenderServiceImpl.java
@@ -21,8 +21,8 @@
/**
 * @author sean.zhou
 * @date 2021/11/16
 * @version 0.1
 * @date 2021/11/16
 */
@Service
@Slf4j
@@ -43,6 +43,7 @@
    public void publish(String topic, CommonTopicResponse response) {
        this.publish(topic, 1, response);
    }
    public void sendRabbitMQ(String topic, Object data) {
        try {
            if (sendRabbitMQ) {
@@ -139,6 +140,35 @@
    }
    @Override
    public <T> ServiceReply<T> publishServicesTopic(TypeReference<T> clazz, String sn, String method, Object data, String bid, Long timestamp) {
        String topic = TopicConst.THING_MODEL_PRE + TopicConst.PRODUCT + sn + TopicConst.SERVICES_SUF;
        ServiceReply reply = this.publishWithReply(ServiceReply.class, topic,
                CommonTopicResponse.builder()
                        .tid(UUID.randomUUID().toString())
                        .bid(StringUtils.hasText(bid) ? bid : UUID.randomUUID().toString())
                        .timestamp(timestamp)
                        .method(method)
                        .data(Objects.requireNonNullElse(data, ""))
                        .build());
        if (Objects.isNull(clazz)) {
            return reply;
        }
        // put together in "output"
        if (Objects.nonNull(reply.getInfo())) {
            reply.setOutput(mapper.convertValue(reply.getInfo(), clazz));
        }
        if (Objects.nonNull(reply.getOutput())) {
            reply.setOutput(mapper.convertValue(reply.getOutput(), clazz));
        }
        return reply;
    }
    @Override
    public ServiceReply publishServicesTopic(String sn, String method, Object data, String bid, Long timestamp) {
        return this.publishServicesTopic(null, sn, method, data, bid, timestamp);
    }
    @Override
    public ServiceReply publishServicesTopic(String sn, String method, Object data, String bid) {
        return this.publishServicesTopic(null, sn, method, data, bid);
    }
@@ -154,7 +184,7 @@
    }
    @Override
    public  <T> ServiceReply<T> publishRequestsTopic(TypeReference<T> clazz, String sn, String method, Object data, String bid) {
    public <T> ServiceReply<T> publishRequestsTopic(TypeReference<T> clazz, String sn, String method, Object data, String bid) {
        String topic = TopicConst.THING_MODEL_PRE + TopicConst.PRODUCT + sn + TopicConst.REQUESTS_SUF;
        ServiceReply reply = this.publishWithReply(ServiceReply.class, topic,
                CommonTopicResponse.builder()