Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v5 headers missing for QoS 2 subscription #1432

Closed
magnusga opened this issue Sep 26, 2019 · 3 comments

Comments

@magnusga
Copy link

@magnusga magnusga commented Sep 26, 2019

Hi! :)

MQTT v5 headers seems to be missing when I publish and subscribe to messages with QoS 2. However, QoS 0 and 1 works fine. Don't know if this is a problem with the mosquitto broker, or with the client library.

Using mosquitto 1.6.7 Windows x64. Compiling with Visual Studio Community 2017 compiler in a Qt project.

Here's the callback for the client:

void message_v5_callback(struct mosquitto *mosq, void *, const struct mosquitto_message *message, const mosquitto_property *proplist)
{
    char *contentType = nullptr;
    char *responseTopic = nullptr;

    printf("\n");
    printf("QoS: %i\n", message->qos);
    printf("Topic: %s\n", message->topic);

    if (mosquitto_property_read_string(proplist, MQTT_PROP_CONTENT_TYPE, &contentType, false))
    {
        printf("Content-type: %s\n", contentType);
//        free(contentType);
    }

    if (mosquitto_property_read_string(proplist, MQTT_PROP_RESPONSE_TOPIC, &responseTopic, false))
    {
        printf("Response-topic: %s\n", responseTopic);
//        free(responseTopic);
    }

    printf("%.*s\n", message->payloadlen, static_cast<const char *>(message->payload));
}

Here's the publish command:

mosquitto_pub -V 5 -D publish content-type text/plain -D publish response-topic msg/123 -t msg -m hello -q 2

Here are the results for QoS 0, 1 and 2:


QoS: 0
Topic: msg
Content-type: text/plain
Response-topic: msg/123
hello

QoS: 1
Topic: msg
Content-type: text/plain
Response-topic: msg/123
hello

QoS: 2
Topic: msg
hello

QoS 2 is missing headers for content-type and response-topic. Is this a bug in mosquitto? Can anyone reproduce this?

(Unrelated: "free()" has been commented out in the above code snippet because it was causing the program to crash. Don't know if that is a Qt specific problem or what.)

ralight added a commit that referenced this issue Sep 26, 2019
Closes #1432. Thanks to Magnus Galåen.
@ralight

This comment has been minimized.

Copy link
Contributor

@ralight ralight commented Sep 26, 2019

Thanks for the detailed report, this was a bug which is now fixed in the fixes branch. Please feel free to give it a try.

With regards the free causing problems - I haven't been able to reproduce that in my simple command line only test programs. If you still have that problem I'd be interested in making sure it isn't something in the library.

@magnusga

This comment has been minimized.

Copy link
Author

@magnusga magnusga commented Sep 26, 2019

Nice! Thank you! I will test it on Monday. And regarding free, I will do some more tests on Monday as well. Compile without Qt etc. And open a new issue if it's relevant.

@magnusga

This comment has been minimized.

Copy link
Author

@magnusga magnusga commented Sep 30, 2019

I have tested it on my setup, and it works great. Also the free issue disappeared when compiling mosquitto myself (instead of using the precompiled installer).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.