A common method messages MQTT (V2 version used here) Released:
1, connected via MQTT MQTT server client to establish a long connection, send messages through an interface
The most common clients:
<dependency> <groupId>org.eclipse.paho</groupId> <artifactId>org.eclipse.paho.client.mqttv3</artifactId> <version>1.1.0</version> </dependency>
Example publishing interface (connection process is omitted ...)
// announced the try { MqttMessage the Message = new new MqttMessage (); message.setQos ( 1); // ensure messages reach a message.setRetained ( to true ); message.setPayload ( "I like to do the test, gnaw a pinch" .getBytes ()); client.publish (publishTopic, Message); } the catch (MqttException E) { System.out.println ( "publish Fail" ); e.printStackTrace (); }
2, Rest interfaces provided by MQTT news release
MQTT official website: https://docs.emqx.io/broker/v2/cn/rest.html?highlight=post
postMan simulation
basic auth authentication
Release of body