简体   繁体   English

如何在MQTT传输WSO2消息代理中添加身份验证

[英]How add authentication in MQTT transport WSO2 Message broker

I have created a sample Publish and subscribe model project using the WSO2 Message Broker. 我已经使用WSO2 Message Broker创建了一个示例发布和订阅模型项目。

import threading
import paho.mqtt.client as mqtt

def publish_1(client,topic):
    message="on"
    print("publish data")
    client.publish(topic,message)
    publish_1(client,topic)


broker="localhost"
topic_pub='/temperature123'
topic_sub='$SYS/#'

def on_connect(client, userdata, rc):
    print("Connected with result code "+str(rc))
    client.subscribe(topic_sub)


def on_message(client, userdata, msg):
    print(msg.topic+" "+str(msg.payload))

client = mqtt.Client()
client.on_connect = on_connect
client.on_message = on_message

client.connect(broker, 1883, 60)
thread1=threading.Thread(target=publish_1,args=(client,topic_pub))
thread1.start()

But there is no security in this implementation. 但是此实现没有安全性。

Can someone help me to setup a authentication in MQTT subscription in the WSO2 Message Broker? 有人可以帮助我在WSO2 Message Broker中的MQTT订阅中设置身份验证吗? And i dont see any subscribed node information also in the WSO2 Message broker application https://localhost:9443/carbon 而且我也没有在WSO2消息代理应用程序https:// localhost:9443 / carbon中看到任何订阅的节点信息

My experience is with Mosquitto not with WSO2 MB, but from a quick look at the WSO2 MB documentation it seems to support SSL which is the standard way of securing MQTT ( https://docs.wso2.com/display/MB310/Enabling+SSL+Support ). 我的经验是使用Mosquitto而不是使用WSO2 MB,但是快速浏览一下WSO2 MB文档,它似乎支持SSL,这是保护MQTT的标准方法( https://docs.wso2.com/display/MB310/Enabling+ SSL +支持 )。 The process of doing this is quite simple, just distribute the proper keys and certificates then use tsl_set() to configure them in your script. 这样做的过程非常简单,只需分发适当的密钥和证书,然后使用tsl_set()在脚本中进行配置即可。

If you require subtler user / topic level controls it looks like they are provided through the larger WSO2 framework ( https://docs.wso2.com/pages/viewpage.action?pageId=30540550#SecurityinWSO2MessageBroker/ApacheQpid-Auth ). 如果您需要更好的用户/主题级别的控件,则看起来它们是通过较大的WSO2框架提供的( https://docs.wso2.com/pages/viewpage.action?pageId=30540550#SecurityinWSO2MessageBroker/ApacheQpid-Auth )。 But I will leave it someone with more experience with WSO2 to explain your options there. 但是,我会留给有更多WSO2经验的人在那儿解释您的选择。

Edit: As an aside, it is seen as a bad practice to start a topic with a / because it creates a confusing / layer. 编辑:顺便说一句,以/开头的主题被视为一种不好的做法,因为它会创建一个混乱的/层。 I would just write the topic as "temperature123" 我只是将主题写为“ temperature123”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM