@Override public String toString() { StringBuilder sb = new StringBuilder(getNamespace()).append("/") .append(getGroupId()).append("/") .append(getType()).append("/") .append(getEdgeNodeId()); if (getDeviceId() != null) { sb.append("/").append(getDeviceId()); } return sb.toString(); }
@Override public void messageArrived(String topic, MqttMessage message) throws Exception { Topic sparkplugTopic = TopicUtil.parseTopic(topic); ObjectMapper mapper = new ObjectMapper(); mapper.setSerializationInclusion(Include.NON_NULL); System.out.println("Message Arrived on Sparkplug topic " + sparkplugTopic.toString()); SparkplugBPayloadDecoder decoder = new SparkplugBPayloadDecoder(); SparkplugBPayload inboundPayload = decoder.buildFromByteArray(message.getPayload()); // Convert the message to JSON and print to system.out try { String payloadString = mapper.writeValueAsString(inboundPayload); System.out.println(mapper.writerWithDefaultPrettyPrinter().writeValueAsString(inboundPayload)); } catch (Exception e) { e.printStackTrace(); } }
public void messageArrived(String topic, MqttMessage message) throws Exception { Topic sparkplugTopic = TopicUtil.parseTopic(topic); ObjectMapper mapper = new ObjectMapper(); mapper.setSerializationInclusion(Include.NON_NULL); SparkplugBPayloadDecoder decoder = new SparkplugBPayloadDecoder(); SparkplugBPayload inboundPayload = decoder.buildFromByteArray(message.getPayload()); if (sparkplugTopic.isType(MessageType.NBIRTH)) { try { System.out.println("\n\nRecieved Node Birth"); System.out.println(mapper.writerWithDefaultPrettyPrinter().writeValueAsString(inboundPayload)); System.out.print("\n\n> "); } catch (Exception e) { e.printStackTrace(); } } }