| | |
| | | |
| | | /** |
| | | * @author sean.zhou |
| | | * @date 2021/11/16 |
| | | * @version 0.1 |
| | | * @date 2021/11/16 |
| | | */ |
| | | @Service |
| | | @Slf4j |
| | |
| | | public void publish(String topic, CommonTopicResponse response) { |
| | | this.publish(topic, 1, response); |
| | | } |
| | | |
| | | public void sendRabbitMQ(String topic, Object data) { |
| | | try { |
| | | if (sendRabbitMQ) { |
| | |
| | | } |
| | | |
| | | @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); |
| | | } |