Skip to content

Enhancements to the pub sub client reconnect unsubscribe publish with time out #128

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
wants to merge 14 commits into
base: main
Choose a base branch
from

Conversation

moamenvx
Copy link

@moamenvx moamenvx commented Apr 10, 2025

Describe your changes

Issue ticket number and link

Checklist - Manual tasks

  • Examples are executing successfully

  • Created/updated unit tests. Code Coverage percentage on new code shall be >= 80%.

  • Created/updated integration tests.

  • Devcontainer can be opened successfully

  • Devcontainer can be opened successfully behind a corporate proxy

  • Devcontainer can be re-built successfully

  • Extended the documentation (e.g. README.md, CONTRIBUTING.md, Velocitas Docs)

Copy link
Member

@BjoernAtBosch BjoernAtBosch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi moamenvx,
thx for your 1st contribution. Looks meaningful.
However, there are some findings to be fixed.
Regards, Björn

Comment on lines 62 to 70
/**
* @brief Status of an MQTT publish operation
*/
enum PublishStatus {
Success, // Message was published successfully
Timeout, // Publish operation timed out
Failure // Publish operation failed (e.g., exception thrown)
};

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not used here. Should be moved to IPubSubClient.h

Comment on lines +107 to +113
/**
* @brief Reconnect the client to the broker.
* @param timeout_ms maximum time to wait for the reconnection attempt to complete, in
* milliseconds.
*/
virtual void reconnect(int timeout_ms) = 0;

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should not be visible to the app "user" code: Instead, reconnection should be done "under the hood" within the PubSubClient after calling connect() and until calling disconnect().
Would be cool if you could achieve that. There is also longer on our minds, that currently the app is terminating if there is no mqtt connection available at startup. Better behaviour would be, that the app is just silently waiting and connecting to the mqtt broker once it gets available.

Comment on lines 21 to 25
<<<<<<< HEAD
|lxml|5.3.2|New BSD|
=======
|lxml|5.3.1|New BSD|
>>>>>>> ad99c59d1940332b4c003f40072511903b40cacd
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please fix this merge conflict
You can get the required content just from the output of the failing workflow. There is a section where you can copy the content from. Just past it over the existing content of this file. Make sure there is exactly one single FF after the last license entry!

*
* @param topic the MQTT topic to publish the message to
* @param data the payload to send as the message
* @param timeout_ms maximum time to wait for the publish to complete, in milliseconds
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please document the corner cases: What does a timeout of 0 ms mean? What about negative numbers?

@@ -93,6 +109,36 @@ class MqttPubSubClient : public IPubSubClient, private mqtt::callback {
m_client.publish(topic, data)->wait();
}

PublishStatus publishOnTopic(const std::string& topic, const std::string& data,
int timeout_ms) override {
try {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know the existing function is block-waiting, but for this new function it could make sense to return a future or a AsyncResult to let the user decide if they like to do blocking wait or will use Callbacks for async notification (or likes to ignore outcome at all).

In case of keeping the blocking variant, you should think about using Paho mqtt's waitFor() ...

@moamenvx
Copy link
Author

moamenvx commented Apr 10, 2025 via email

@moamenvx moamenvx marked this pull request as draft April 15, 2025 11:53
@moamenvx moamenvx marked this pull request as ready for review April 15, 2025 12:08
@moamenvx moamenvx requested a review from BjoernAtBosch April 16, 2025 07:01
Copy link
Member

@BjoernAtBosch BjoernAtBosch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi moamenvx,
please revert your changes regarding indentation and include order. This is handled by our tooling.
Furthermore, it makes it hard to understand the real code changes. (In general, those kind of changes should not be intermixed with real behavioral changes.)
Will continue reviewing once those changes are reverted.

@moamenvx moamenvx requested a review from BjoernAtBosch April 16, 2025 11:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants