Giter Club home page Giter Club logo

Comments (13)

kqkdChen avatar kqkdChen commented on May 22, 2024 1

单次发送

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)

from iotdb.

vesense avatar vesense commented on May 22, 2024 1

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

from iotdb.

jixuan1989 avatar jixuan1989 commented on May 22, 2024 1

@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.

from iotdb.

kqkdChen avatar kqkdChen commented on May 22, 2024 1

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

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

from iotdb.

jixuan1989 avatar jixuan1989 commented on May 22, 2024

Many thanks. @vesense can you have a look?

from iotdb.

vesense avatar vesense commented on May 22, 2024

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

from iotdb.

kqkdChen avatar kqkdChen commented on May 22, 2024

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

谢谢,这个插入错误的问题我已经解决了,然后你能先帮我看这个新问题吗?这个比较重要,涉及到mqtt连接的身份验证失效#1446

from iotdb.

vesense avatar vesense commented on May 22, 2024

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

@kqkdChen 这个问题已经好了?发生了什么?

from iotdb.

vesense avatar vesense commented on May 22, 2024

使用 python paho mqtt 插入数据时,没有设置用户名和密码相关参数仍然成功的插入了

这是由于当前默认允许匿名用户访问。这会存在一定的安全隐患,我会提一个patch来解决。

from iotdb.

kqkdChen avatar kqkdChen commented on May 22, 2024

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

@kqkdChen 这个问题已经好了?发生了什么?

我换了另外一种方法写了mqtt client端的代码,所以就没有出现上述的错误了,所以这个问题应该是代码编写不规范造成的。然后我希望官网可以多一些其他语言的demo,我也会展示我的代码,希望可以帮助更多的人

from iotdb.

vesense avatar vesense commented on May 22, 2024

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

from iotdb.

jerrychong25 avatar jerrychong25 commented on May 22, 2024

单次发送

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)

@kqkdChen 你好!

我想问在IoTDB Python Client遇到的MQTT Publish写入问题,我尝试写入2行Records但是IoTDB没成功保存。MQTT这里使用Port 2833,因为已有另一个MQTT Broker占用Port 1883。而且没有任何IoTDB报错。

Python MQTT Client代码:
58baa2b462a3869a1fd8163be9dc24e

IoTDB MQTT Configuration:
0399e3cb358d0201046bcaabb2f0e8d

也尝试使用apache-iotdb pypi library session.insert_record() 测试存入一样的Records,IoTDB成功保存。

这个问题要怎么解决呢?

谢谢!

from iotdb.

jerrychong25 avatar jerrychong25 commented on May 22, 2024

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

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

好的,谢谢 @kqkdChen !

from iotdb.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.