我使用paho.mqtt,并将消息发送到主题test/data/user1
我的订阅客户端:
from paho.mqtt import client as mqtt_client
host = 'myhost.com'
port = 1883
topic = 'test/data/#'
auth = {
'username': 'myuser',
'password': 'mypass'
}
client_id = 'python-mqtt-1'
def connect_mqtt() -> mqtt_client:
def on_connect(client, userdata, flags, rc):
if rc == 0:
print("Connected to MQTT Broker!")
else:
print("Failed to connect, return code %d\n", rc)
client = mqtt_client.Client(client_id)
client.username_pw_set(**auth)
client.on_connect = on_connect
client.connect(host, port)
return client
def subscribe(client: mqtt_client):
def on_message(client, userdata, msg):
print(f"Received `{msg.payload.decode()}` from `{msg.topic}` topic")
client.subscribe(topic)
client.on_message = on_message
def run():
client = connect_mqtt()
subscribe(client)
client.loop_forever()
if __name__ == '__main__':
run()
但是我用topic='test/data/#'
没有得到我的消息。如果我用topic='test/data/user1'
,我得到我的消息。为什么通配符主题不起作用?
我的经纪人是RabbitMQ。
1条答案
按热度按时间cvxl0en21#
所以很显然RabbitMQ本身并不支持这个特性。
https://github.com/rabbitmq/rabbitmq-server/issues/2556