Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-104478

Mqtt topic wildcard failure

    XMLWordPrintable

Details

    • Linux/X11
    • 95b38eafb (dev), 81854688b (6.6), 0ea88f582 (tqtc/lts-6.5), a599d5a71 (tqtc/lts-6.2)

    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

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            mkalinow Maurice Kalinowski
            eguesnet Guesnet Etienne
            Votes:
            1 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes