Search code examples
pythonrabbitmqmqttwildcardpaho

Why don't wildcard topics (#, +) work in Python paho MQTT Subscribe with retained messages?


I use paho.mqtt. And I send messange to topic test/data/user1

My Subscribe Client:

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

But I don't get my messange with topic='test/data/#'. If I use topic='test/data/user1', I get my messange. Why is the wildcard theme not working?

My broker is RabbitMQ.


Solution

  • So apparently RabbitMQ itself doesn't support this feature.

    https://github.com/rabbitmq/rabbitmq-server/issues/2556