From 3ba2ea4de914835bc316826f2c7f93a648760e9c Mon Sep 17 00:00:00 2001
From: guoshilong <123456>
Date: Tue, 26 Sep 2023 16:24:56 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/main'
---
src/main/java/com/dji/sample/component/mqtt/service/impl/MessageSenderServiceImpl.java | 37 ++++++++++++++++++++++++++++++++++++-
1 files changed, 36 insertions(+), 1 deletions(-)
diff --git a/src/main/java/com/dji/sample/component/mqtt/service/impl/MessageSenderServiceImpl.java b/src/main/java/com/dji/sample/component/mqtt/service/impl/MessageSenderServiceImpl.java
index fdaf62c..237713c 100644
--- a/src/main/java/com/dji/sample/component/mqtt/service/impl/MessageSenderServiceImpl.java
+++ b/src/main/java/com/dji/sample/component/mqtt/service/impl/MessageSenderServiceImpl.java
@@ -71,7 +71,7 @@
response.setBid(UUID.randomUUID().toString());
response.setTid(UUID.randomUUID().toString());
}
- throw new RuntimeException("No message reply received.");
+ throw new RuntimeException("没有收到消息回复。");
}
@Override
@@ -113,4 +113,39 @@
return this.publishServicesTopic(null, sn, method, data, null);
}
+ @Override
+ 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()
+ .tid(UUID.randomUUID().toString())
+ .bid(StringUtils.hasText(bid) ? bid : UUID.randomUUID().toString())
+ .timestamp(System.currentTimeMillis())
+ .gateway(sn)
+ .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 publishRequestsTopic(String sn, String method, Object data, String bid) {
+ return this.publishRequestsTopic(null, sn, method, data, bid);
+ }
+
+ @Override
+ public ServiceReply publishRequestsTopic(String sn, String method, Object data) {
+ return this.publishRequestsTopic(null, sn, method, data, null);
+ }
+
}
\ No newline at end of file
--
Gitblit v1.9.3