You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@iotdb.apache.org by GitBox <gi...@apache.org> on 2020/06/30 09:48:35 UTC

[GitHub] [incubator-iotdb] kqkdChen opened a new issue #1442: failed to insert data using python paho mqtt library

kqkdChen opened a new issue #1442:
URL: https://github.com/apache/incubator-iotdb/issues/1442


   使用 python paho mqtt 插入数据时出现错误:
   client_id不能为空,且qos必须等于0,不然就会出现错误。
   
   qos=1 or 2, 则会出现如下错误,结果就是预期应该插入10W条数据的结果只插入了20条数据
   ![image](https://user-images.githubusercontent.com/41674301/86111404-47a77000-baf9-11ea-870b-cd7b3e5ba2e2.png)
   
   iotdb version: 0.10.0
   paho-mqtt: 1.5.0
   
   代码如下
   
   ```python
   import random
   
   import paho.mqtt.client as mqtt
   import time
   
   
   def on_connect(client, userdata, flags, rc):
       print("Connected with result code: " + str(rc))
   
   
   def on_message(client, userdata, msg):
       print(msg.topic + " " + str(msg.payload))
   
   
   client = mqtt.Client(client_id=str(random.uniform(1, 10)))
   # client = mqtt.Client()
   client.username_pw_set("root", "root")
   client.connect('127.0.0.1', 1883)
   
   timestamp = lambda: int(round(time.time() * 1000))
   for i in range(100000):
       message = "{\n" "\"device\":\"root.log.d1\",\n" "\"timestamp\":%d,\n" "\"measurements\":[\"s1\"],\n" "\"values" \
                 "\":[%f]\n" "}" % (timestamp() + 1000 * i, random.uniform(1, 10))
       client.publish('root.log.d1.info', payload=message, qos=0, retain=False)
   client.disconnect()
   
   ```


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-iotdb] kqkdChen edited a comment on issue #1442: failed to insert data using python paho mqtt library

Posted by GitBox <gi...@apache.org>.
kqkdChen edited a comment on issue #1442:
URL: https://github.com/apache/incubator-iotdb/issues/1442#issuecomment-652326040


   单次发送
   ```python
   from time import *
   import paho.mqtt.publish as publish
   
   
   def timestamp():
       return int(round(time() * 1000))
   
   
   def single(tx_id: str, log_type: str, log_content: str, hostname: str = "192.168.3.181", port: int = 1883):
       device_id = "root.log.%s" % tx_id
       payload = "{\n" "\"device\":\"%s\",\n" "\"timestamp\":%d,\n" "\"measurements\":[\"type\",\"content\"],\n" "\"values" \
                 "\":[\"%s\",\"%s\"]\n" "}" % (device_id, timestamp(), log_type, log_content)
       publish.single(topic=device_id, payload=payload, hostname=hostname, port=port)
   
   
   if __name__ == '__main__':
       type_list = ["INFO", "WARNING", "ERROR"]
       content_list = ["content_1", "content_2", "content_3", "content_4"]
       begin_time = time()
       for i in range(10):
           single("1411111111", type_list[i % len(type_list)], content_list[i % len(content_list)])
       end_time = time()
       run_time = end_time - begin_time
       print('cost time:', run_time)
   ```


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-iotdb] vesense commented on issue #1442: failed to insert data using python paho mqtt library

Posted by GitBox <gi...@apache.org>.
vesense commented on issue #1442:
URL: https://github.com/apache/incubator-iotdb/issues/1442#issuecomment-652328543


   目前官网的示例主要是Java,其他语言的Demo(如Python,C++等)比较欠缺,欢迎你把示例贡献到社区,让更多人看到。


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-iotdb] kqkdChen commented on issue #1442: failed to insert data using python paho mqtt library

Posted by GitBox <gi...@apache.org>.
kqkdChen commented on issue #1442:
URL: https://github.com/apache/incubator-iotdb/issues/1442#issuecomment-652326040


   单条插入
   ```python
   from time import *
   import paho.mqtt.publish as publish
   
   
   def timestamp():
       return int(round(time() * 1000))
   
   
   def single(tx_id: str, log_type: str, log_content: str, hostname: str = "192.168.3.181", port: int = 1883):
       device_id = "root.log.%s" % tx_id
       payload = "{\n" "\"device\":\"%s\",\n" "\"timestamp\":%d,\n" "\"measurements\":[\"type\",\"content\"],\n" "\"values" \
                 "\":[\"%s\",\"%s\"]\n" "}" % (device_id, timestamp(), log_type, log_content)
       publish.single(topic=device_id, payload=payload, hostname=hostname, port=port)
   
   
   if __name__ == '__main__':
       type_list = ["INFO", "WARNING", "ERROR"]
       content_list = ["content_1", "content_2", "content_3", "content_4"]
       begin_time = time()
       for i in range(10):
           single("1411111111", type_list[i % len(type_list)], content_list[i % len(content_list)])
       end_time = time()
       run_time = end_time - begin_time
       print('cost time:', run_time)
   ```


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-iotdb] vesense commented on issue #1442: failed to insert data using python paho mqtt library

Posted by GitBox <gi...@apache.org>.
vesense commented on issue #1442:
URL: https://github.com/apache/incubator-iotdb/issues/1442#issuecomment-652281347


   Thanks @kqkdChen for your report. I will take a look ASAP.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-iotdb] vesense commented on issue #1442: failed to insert data using python paho mqtt library

Posted by GitBox <gi...@apache.org>.
vesense commented on issue #1442:
URL: https://github.com/apache/incubator-iotdb/issues/1442#issuecomment-652321999


   @kqkdChen Thanks again for your report and look forward to your more feedback.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-iotdb] kqkdChen commented on issue #1442: failed to insert data using python paho mqtt library

Posted by GitBox <gi...@apache.org>.
kqkdChen commented on issue #1442:
URL: https://github.com/apache/incubator-iotdb/issues/1442#issuecomment-652293863


   > Thanks @kqkdChen for your report. I will take a look ASAP.
   
   谢谢,这个插入错误的问题我已经解决了,然后你能先帮我看这个新问题吗?**这个比较重要,涉及到mqtt连接的身份验证失效**。 #1446 


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-iotdb] vesense removed a comment on issue #1442: failed to insert data using python paho mqtt library

Posted by GitBox <gi...@apache.org>.
vesense removed a comment on issue #1442:
URL: https://github.com/apache/incubator-iotdb/issues/1442#issuecomment-652321999


   @kqkdChen Thanks again for your report and look forward to your more feedback.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-iotdb] kqkdChen edited a comment on issue #1442: failed to insert data using python paho mqtt library

Posted by GitBox <gi...@apache.org>.
kqkdChen edited a comment on issue #1442:
URL: https://github.com/apache/incubator-iotdb/issues/1442#issuecomment-652324556


   > > qos=1 or 2, 则会出现如下错误,结果就是预期应该插入10W条数据的结果只插入了20条数据
   > 
   > @kqkdChen 这个问题已经好了?发生了什么?
   
   我换了另外一种方法写了mqtt client端的代码,所以就没有出现上述的错误了,所以这个问题应该是代码编写不规范造成的。然后我希望官网可以多一些其他语言的demo,我也会展示我的代码,希望可以帮助更多的人


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-iotdb] vesense closed issue #1442: failed to insert data using python paho mqtt library

Posted by GitBox <gi...@apache.org>.
vesense closed issue #1442:
URL: https://github.com/apache/incubator-iotdb/issues/1442


   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-iotdb] kqkdChen commented on issue #1442: failed to insert data using python paho mqtt library

Posted by GitBox <gi...@apache.org>.
kqkdChen commented on issue #1442:
URL: https://github.com/apache/incubator-iotdb/issues/1442#issuecomment-652324556


   > > qos=1 or 2, 则会出现如下错误,结果就是预期应该插入10W条数据的结果只插入了20条数据
   > 
   > @kqkdChen 这个问题已经好了?发生了什么?
   
   我换了另外一种方法写了mqtt client端的代码,所以就没有出现上述的错误了,然后我希望官网可以多一些其他语言的demo,我也会展示我的代码,希望可以帮助更多的人


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-iotdb] vesense commented on issue #1442: failed to insert data using python paho mqtt library

Posted by GitBox <gi...@apache.org>.
vesense commented on issue #1442:
URL: https://github.com/apache/incubator-iotdb/issues/1442#issuecomment-652314354


   > qos=1 or 2, 则会出现如下错误,结果就是预期应该插入10W条数据的结果只插入了20条数据
   
   @kqkdChen 这个问题已经好了?发生了什么?


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-iotdb] vesense edited a comment on issue #1442: failed to insert data using python paho mqtt library

Posted by GitBox <gi...@apache.org>.
vesense edited a comment on issue #1442:
URL: https://github.com/apache/incubator-iotdb/issues/1442#issuecomment-652328543


   目前官网的示例主要是Java,其他语言的Demo(如Python,C++等)比较欠缺,欢迎你把示例贡献到社区(可以提patch到documents),让更多人看到。


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-iotdb] jixuan1989 commented on issue #1442: failed to insert data using python paho mqtt library

Posted by GitBox <gi...@apache.org>.
jixuan1989 commented on issue #1442:
URL: https://github.com/apache/incubator-iotdb/issues/1442#issuecomment-652266143


   Many thanks. @vesense  can you have a look?


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-iotdb] jixuan1989 commented on issue #1442: failed to insert data using python paho mqtt library

Posted by GitBox <gi...@apache.org>.
jixuan1989 commented on issue #1442:
URL: https://github.com/apache/incubator-iotdb/issues/1442#issuecomment-652748811


   @kqkdChen 欢迎贡献example到官网用户手册。 
   
   修改`docs/UserGuide/Client/Programming - MQTT.md`,以及`docs/zh/UserGuide/Client/Programming - MQTT.md` (英文版和中文版)并提交PR即可。
   
   例如,在该markdown末尾增加
   ```markdown
   ##Example (Python)
   粘贴你的代码(要增加一些说明,尽可能让代码易懂)
   
   ```
   
   等我们的ptyon 集成测试框架搞定后,会考虑把python的样例代码放入源码中,每次构建时进行测试,确保不出错。
   
   Welcome to posting your examples to the official website. just modify `docs/UserGuide/Client/Programming - MQTT.md` and `docs/zh/UserGuide/Client/Programming - MQTT.md`.
   
   By the way, we are planning to develop the UT framework for Python, and after that, we may put the example codes to the source folder and consider it as a check step for each code repo update.
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-iotdb] vesense commented on issue #1442: failed to insert data using python paho mqtt library

Posted by GitBox <gi...@apache.org>.
vesense commented on issue #1442:
URL: https://github.com/apache/incubator-iotdb/issues/1442#issuecomment-652793656


   @kqkdChen Thanks again for your report and look forward to your more feedback and contributions.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org