[ https://issues.apache.org/jira/browse/IOTDB-1220?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17332989#comment-17332989 ]
刘珍 commented on IOTDB-1220: --------------------------- master commit f585d02a3cbe217caaab41de43e22570f4b0db8f Author: Haonan <hhao...@outlook.com> Date: Tue Apr 27 13:35:29 2021 +0800 [IOTDB-1220] MQTT example may have timestamp precision issue (#3074) Resolved。 > MQTT insert 10 rows ,elapsed time is 5s ,and the inserted row count is less > than 10. > ------------------------------------------------------------------------------------ > > Key: IOTDB-1220 > URL: https://issues.apache.org/jira/browse/IOTDB-1220 > Project: Apache IoTDB > Issue Type: Bug > Components: Server > Reporter: 刘珍 > Priority: Minor > Labels: pull-request-available > > master branch. > commit id :5fcff40f2299caeb0c8a9ae42f68bc18ecf8fee7 > > # > ## Usage > * Update configuration to enable MQTT service. (`enable_mqtt_service=true` > in iotdb-engine.properties) > * Launch the IoTDB server. > * Setup storage group `SET STORAGE GROUP TO root.sg` and create time > timeseries `CREATE TIMESERIES root.sg.d1.s1 WITH DATATYPE=DOUBLE, > ENCODING=PLAIN`. > * Run `org.apache.iotdb.mqtt.MQTTClient` to run the mqtt client and send > events to server. > cat ../../src/main/java/org/apache/iotdb/mqtt/MQTTClient.java > > {code:java} > package org.apache.iotdb.mqtt; > import org.fusesource.mqtt.client.BlockingConnection; > import org.fusesource.mqtt.client.MQTT; > import org.fusesource.mqtt.client.QoS; > import java.util.Random; > public class MQTTClient { > public static void main(String[] args) throws Exception { > MQTT mqtt = new MQTT(); > mqtt.setHost("127.0.0.1", 1883); > mqtt.setUserName("root"); > mqtt.setPassword("root"); > BlockingConnection connection = mqtt.blockingConnection(); > connection.connect(); > Random random = new Random(); > for (int i = 0; i < 10; i++) { > String payload = > String.format( > "{\n" + "\"device\":\"root.sg.d1\",\n" + "\"timestamp\":%d,\n" > + "\"measurements\":[\"s1\"],\n" + "\"values\":[%f]\n" + "}", > System.currentTimeMillis(), random.nextDouble()); > connection.publish("root.sg.d1.s1", payload.getBytes(), > QoS.AT_LEAST_ONCE, false); > } > connection.disconnect(); > } > } > {code} > > run time java -classpath ".:...." org/apache/iotdb/mqtt/MQTTClient > 2 times,the elapsed time: > real 0m5.573s > user 0m0.352s > sys 0m0.055s > real 0m0.584s > user 0m0.371s > sys 0m0.039s > > IoTDB> select s1 from root.sg.d1; > +------------------------------+------------+ > |Time|root.sg.d1.s1| > +------------------------------+------------+ > |2021-03-12T11:52:50.687+08:00|0.338776| > |2021-03-12T11:52:50.692+08:00|0.250776| > |2021-03-12T11:52:50.694+08:00|0.575861| > |2021-03-12T11:52:50.695+08:00|0.229369| > |2021-03-12T11:52:50.696+08:00|0.149007| > |2021-03-12T11:52:50.697+08:00|0.182348| > |2021-03-12T11:52:50.698+08:00|0.334755| > |2021-03-12T11:52:50.699+08:00|0.757181| > |2021-03-12T11:53:02.649+08:00|0.618037| > |2021-03-12T11:53:02.655+08:00|0.789077| > |2021-03-12T11:53:02.656+08:00|0.797554| > |2021-03-12T11:53:02.657+08:00|0.660189| > |2021-03-12T11:53:02.658+08:00|0.70841| > |2021-03-12T11:53:02.659+08:00|0.044449| > |2021-03-12T11:53:02.660+08:00|0.130961| > +------------------------------+------------+ > Total line number = 15 > It costs 0.014s > the "Total line number" should be 20. -- This message was sent by Atlassian Jira (v8.3.4#803005)