| | |
| | | response.setBid(UUID.randomUUID().toString()); |
| | | response.setTid(UUID.randomUUID().toString()); |
| | | } |
| | | throw new RuntimeException("No message reply received."); |
| | | throw new RuntimeException("没有收到消息回复。"); |
| | | } |
| | | |
| | | @Override |
| | |
| | | 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); |
| | | } |
| | | |
| | | } |