question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

failed to insert data using python paho mqtt library

See original GitHub issue

使用 python paho mqtt 插入数据时出现错误: client_id不能为空,且qos必须等于0,不然就会出现错误。

qos=1 or 2, 则会出现如下错误,结果就是预期应该插入10W条数据的结果只插入了20条数据 image

iotdb version: 0.10.0 paho-mqtt: 1.5.0

代码如下

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()

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:13 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
kqkdChencommented, Dec 6, 2022

@jerrychong25 你好,已经过去太久具体api用法我忘记了,但是我想说的是,监测一下client的connectsuccesserror 等回调方法,判断连接是否成功。如下是一些使用MQTT服务器的建议:

  • 编写client的回调方法,确认连接是否成功,以及定位连接异常。
  • mqtt_hander_pool_size=1 请设置更大。在IotDB的MQTT组件里,消息的处理使用了一个无界队列缓冲,默认配置会导致消息堆积最终导致IotDB OOM,线上引发过血案,不知道他们修复这个不合理的地方没有。
1reaction
jixuan1989commented, Jul 2, 2020

@kqkdChen 欢迎贡献example到官网用户手册。

修改docs/UserGuide/Client/Programming - MQTT.md,以及docs/zh/UserGuide/Client/Programming - MQTT.md (英文版和中文版)并提交PR即可。

例如,在该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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

failed to insert data using python paho mqtt library #1442
我想问在IoTDB Python Client遇到的MQTT Publish写入问题,我尝试写入2行Records但是IoTDB没成功保存。MQTT这里使用Port 2833,因为已有另一个MQTT Broker ...
Read more >
Import Error: paho.mqtt.client not found - Stack Overflow
I think I have found the problem,. You have installed Python3 but for some reason the interpreter defaults to version 2.7 in Linux....
Read more >
How to Use The Paho MQTT Python Client - Beginners Guide
In this tutorial we look at the Paho MQTT Python Client. Using an example python script and the online Mosquitto broker to subscribe...
Read more >
IoT Platform:Use the Paho MQTT library for Python to connect ...
This function is used to obtain the following MQTT connection parameters: mqttUsername, mqttPassword, and mqttClientId. Input parameters: ...
Read more >
How to use MQTT in Python (Paho) | EMQ
This article introduces how to use the Paho MQTT client library in the Python project, and implements connection, subscribe, messaging, etc of MQTT....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found