Skip to content

msg->get_properties() not working in message_arrived #505

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

Open
greg887 opened this issue Jul 13, 2024 · 7 comments
Open

msg->get_properties() not working in message_arrived #505

greg887 opened this issue Jul 13, 2024 · 7 comments
Labels
cant reproduce Unable to reproduce
Milestone

Comments

@greg887
Copy link

greg887 commented Jul 13, 2024

Is there a bug in msg->get_properties() ?
Am I doing anything wrong?
I looked at the properties samples and I'm using it in the same way.
I tried different brokers thinking something in the broker could be wrong and I get the same results. I also installed the latest mosquitto broker in my laptop and used localhost as broker and it didn't work.

properties in paho cpp are not working when I use msg->get_properties() in message_arrived, but properties in message_arrive work in python.
I run both subscribers the python version and the cpp version at the same time subscribing to the same topic (the publisher is in c++)

** Subscriber python version output:**
Received message: Hello, MQTT! on topic ggg/test/topic
Message Properties:
[UserProperty : [('key1', 'value1'), ('key2', 'value2')]]

** Subscriber c++ output:**
Message arrived: ggg/test/topic -> Hello, MQTT!
No hay user property, porqueeee?? (This means "There is no user property, whyyyy?" )
Is props empty? '1'
props size: '0'

Below is my c++ subscriber message_arrived code
` void message_arrived(mqtt::const_message_ptr msg) override {
std::cout << "Message arrived: " << msg->get_topic() << " -> " << msg->to_string() << std::endl;

    const mqtt::properties& props = msg->get_properties();

    if (props.contains(mqtt::property::USER_PROPERTY)){
        std::cout << "Lo logrè, mamà\n" << std::endl;
    }
    else {
        std::cout << "No hay user property, porqueeee??" << std::endl;
    }

    std::cout << "Is props empty? '" << props.empty() << "'" << std::endl;
    std::cout << "props size: '" << props.size() << "'" << std::endl;

}`

Please kindly help!

@greg887 greg887 closed this as completed Jul 13, 2024
@greg887 greg887 reopened this Jul 13, 2024
@fpagliughi
Copy link
Contributor

I was working on properties recently. Hopefully I didn’t add a bug.

What version of the library are you using?

@greg887
Copy link
Author

greg887 commented Jul 13, 2024

const uint32_t VERSION = 0x01030001;
/** The version string for the client library  */
const string VERSION_STR("Paho MQTT C++ (mqttpp) v. 1.3.1");

thanks for all the amazing work!

@fpagliughi
Copy link
Contributor

It seems to be working fine in the latest 'develop' branch, which I'm working on at the moment (for the next v1.5 release). I'll double check v1.3.1 to see what I can can find, but I don't see any modifications in the message class that would explain it; nor anything in the changelog mentioning a fix.

But just FYI, I've recently dropped a bunch of stuff in the code to make it easier to deal with properties on incoming messages and server responses. Like an iterator for properties and a few more methods to get it to act like an STL collection, like begin(), end(), etc. Plus a stream inserter for property for printing them out.

@greg887
Copy link
Author

greg887 commented Jul 14, 2024

I just installed v1.4.0 and I'm still getting the same error, I removed paho 1.3.1 and re-install paho.

Do you have any estimate of when v1.5 could be released?

Those are going to be great features.

Thanks!

@fpagliughi fpagliughi added this to the v1.5.2 milestone Feb 27, 2025
@fpagliughi
Copy link
Contributor

Sorry. Totally forgot about this. I’ll verify as part of the next patch release to see if it was actually fixed.

@fpagliughi
Copy link
Contributor

Apologies. I was never able to recreate this problem, so I decided to make a new example app, async_subscribe_v5 to show it working.

When I made the example app, I had the same problem! No properties. But then I realized that I was connecting to the broker and requesting an MQTT v3.1.1 connection. So I was getting the messages, but no properties in them.

I suspect, maybe, that's what you did... connected using MQTT v3.x.

When you do that, you still get messages that a v5 producer sent to the broker, but you get them with the v5 properties and reason code stripped out.

@fpagliughi fpagliughi added the cant reproduce Unable to reproduce label Mar 11, 2025
@greg887
Copy link
Author

greg887 commented Mar 11, 2025

I'll check within this week or next week and let you know what I could see, but thanks for the insight.

@fpagliughi fpagliughi modified the milestones: v1.5.2, v1.6 Mar 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cant reproduce Unable to reproduce
Projects
None yet
Development

No branches or pull requests

2 participants