MQTT的协调生产者消费者

mqtt-coordinated的Python项目详细描述


##MQTT协调消费者。

卡夫卡激励的MQTT协调消费者

pip安装mqtt coordinated

##MQTT用户协调管理器

CoordinatorManager类是MQTT使用者的管理器类。它允许您连接到mqtt服务器并订阅多个主题。它会在收到新消息后为操作提供on-u消息回调。

` >>> from mqtt import CoordinatorManager >>> >>> manager = CoordinatorManager('my-manager', 'iot.eclipse.org') >>> manager.start() >>> >>> consumer = manager.coordinated_consumer >>> consumer.on_message = on_message  # Pass callback name here. >>> consumer.subscribe("house/bulb") >>> consumer.poll(100)    # Batch message reading construct for streaming purpose `

` # Disconnect and stop consuming >>> consumer.disconnect() >>> manager.stop() `

有两种消费事件的方法, -正在注册on-u消息 -分批阅读邮件。批处理存储在内存中,暂时不存储在永久性磁盘上。

##MQTT生产者协调生产者

coordinatedproducer类是mqtt producer,它将在mqtt主题上创建多个分区。您可以将分区号或分区密钥传递给此生产者。具有相同分区密钥的消息被允许在同一分区上生成。

` >>> from mqtt import CoordinatedProducer >>> producer = CoordinatedProducer('iot.eclipse.org') >>> producer.publish_on_partition("house/bulb", "on") # Message will be published on random partition >>> producer.publish_on_partition("house/bulb", "on", partition=5) # Message will be published on 5th partition >>> producer.publish_on_partition("house/bulb", "on", partition_key='message_key') # All messages with partition_key will be published on same partition. `

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
安卓 Java LibGDX对内存使用感到困惑   使用@Generated的java自动增量   对名称java:comp/env/jdbc/bar进行间接查找时发生WebSphere NameNotFoundException   Java 8 lambda风格的JDBC语句执行包装器   java如何实现PushCacheFilter   java如何停止和启动jms侦听器   java确定数组中特定元素的总和   JavaJSF:如何使用selectOneRadio立即更新支持bean?   java Exo播放器活动   使类受保护时发生java错误   spring获得java。lang.IllegalArgumentException:只有SSLv3在com中启用。国际商用机器公司jsse2。disableSSLv3设置为TRUE   在java中打印垂直直方图时出现格式错误   Selenium Java处理不同语言和位置以及设置动态体系结构的最佳实践?   java实用程序方法传递文件或字符串?