Details
Description
MQTT wilcard "" does not catch correctly some topic name under specific condition. If a "" and a "#" are used, "+" does not work.
Minimal code to reproduce:
#include <QCoreApplication> #include <QDebug> #include <QMqttClient> #include <QMqttSubscription>int main(int argc, char *argv[]) { QCoreApplication app(argc, argv); QMqttClient client; client.setPort(1883); client.setHostname("localhost"); QObject::connect(&client, &QMqttClient::connected, [&client]() { auto sub1 = client.subscribe( QMqttTopicFilter(QLatin1String("test/#")) ); QObject::connect(sub1, &QMqttSubscription::messageReceived, []( const QMqttMessage& msg ) { qDebug() << "Subscribed to test/#"; qDebug() << "topic : " << msg.topic().name(); qDebug() << "message : " << msg.payload(); } ); auto sub2 = client.subscribe( QMqttTopicFilter(QLatin1String("test/+/#")) ); QObject::connect(sub2, &QMqttSubscription::messageReceived, []( const QMqttMessage& msg ) { qDebug() << "Subscribed to test/+/#"; qDebug() << "topic : " << msg.topic().name(); qDebug() << "message : " << msg.payload(); } ); auto sub3 = client.subscribe( QMqttTopicFilter(QLatin1String("test/+/+")) ); QObject::connect(sub3, &QMqttSubscription::messageReceived, []( const QMqttMessage& msg ) { qDebug() << "Subscribed to test/+/+"; qDebug() << "topic : " << msg.topic().name(); qDebug() << "message : " << msg.payload(); } ); }); client.connectToHost(); return app.exec(); }
Run the binary produced, and with a mosquitto broker initialized, type
mosquitto_pub -m "Wildcard test" -t test/foo/bar
Attempted result :
Subscribed to test/# topic : "test/foo/bar" message : "Wildcard test" Subscribed to test/+/# topic : "test/foo/bar" message : "Wildcard test" Subscribed to test/+/+ topic : "test/foo/bar" message : "Wildcard test"
Obtained:
Subscribed to test/# topic : "test/foo/bar" message : "Wildcard test" Subscribed to test/+/+ topic : "test/foo/bar" message : "Wildcard test"
Subscription to "test/+/#"is missing, whereas "test/foo/bar" follow the ruleset.
Using in parallel three mosquitto subscriber
mosquitto_sub -t test/# mosquitto_sub -t test/+/+ mosquitto_sub -t test/+/#
All of them get the message.
Code to reproduce has been highly inspired from #QTBUG-92817 .
Attachments
For Gerrit Dashboard: QTBUG-104478 | ||||||
---|---|---|---|---|---|---|
# | Subject | Branch | Project | Status | CR | V |
521309,2 | Fix handling of multiple wildcards | dev | qt/qtmqtt | Status: MERGED | +2 | 0 |
522352,2 | Fix handling of multiple wildcards | 6.6 | qt/qtmqtt | Status: MERGED | +2 | 0 |
522410,2 | Fix handling of multiple wildcards | tqtc/lts-6.5 | qt/tqtc-qtmqtt | Status: MERGED | +2 | 0 |
522461,3 | Fix handling of multiple wildcards | tqtc/lts-6.2 | qt/tqtc-qtmqtt | Status: MERGED | +2 | 0 |