emqx / qmqtt

MQTT client for Qt

Home Page:https://www.emqx.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Publisher and Subscriber in the same client

nitol-saha opened this issue · comments

I want to implement 2 clients with feature of publisher and subscriber in the same client.

Client 1: Publisher will send data in every 1 second and subscriber will listen for any incoming message in another topic.

Client 2: Subscriber will receive any data and as soon as it receives the data it will publish the data to another topic.

Can you provide me with any examples? I am new to this library.

Hi nitol-saha,

this library is pretty much in a maintenance-only status. So I would not necessarily suggest it for new code since Qt's embedded mqtt module has been around for a long time now: https://doc.qt.io/qt-6/qtmqtt-index.html.

Maybe @ejvr would like to add something?

commented

The example in the repository does exactly that. It has a Publisher class sending messages on a timer and a Subscriber class listening to the same messages. For your project you only need to change the topics to make it work.

Note that the example creates 2 clients, but as long as you a working with a single broker you only need one.
You can subscribe and publish in the same client.

Thanks for the information! I have started working on it. I will let you know if I face any issue.

Hi nitol-saha,

this library is pretty much in a maintenance-only status. So I would not necessarily suggest it for new code since Qt's embedded mqtt module has been around for a long time now: https://doc.qt.io/qt-6/qtmqtt-index.html.

Maybe @ejvr would like to add something?

I have looked into this documentation: https://doc.qt.io/qtcreator/index.html. Can I write the client code using Qt Editor only? Does Qt-6 has github repository like this one to read the documentation?

I have got this one only.
https://code.qt.io/cgit/qt/qtmqtt.git/

I have looked into this documentation: https://doc.qt.io/qtcreator/index.html. Can I write the client code using Qt Editor only?

Yes, for sure.

Does Qt-6 has github repository like this one to read the documentation?

This should be the place which you where looking for: https://github.com/qt/qtmqtt

I have some general questions about the library to find compatibility for my project. If you can answer the following questions that would be really helpful:

  • Is the library compatible or can be made compatible with ACE (Adaptive Communication Environment) (http://www.dre.vanderbilt.edu/~schmidt/ACE-overview.html)?

  • Is there any dynamic memory allocation (new, delete)?

  • Does the library have threading model or single thread execution?

  • How are the exception handled? (Exception handling should not throw and end execution)

Regarding your questions (@ejvr please feel free to extend):

Is the library compatible or can be made compatible with ACE (Adaptive Communication Environment (http://www.dre.vanderbilt.edu/~schmidt/ACE-overview.html)?

qmqtt makes use of the QSocket resp. QSslSocket classes, which encapsulate the OS-native socket API with a C++-friendlier interface. If ACE is able to wrap the socket syscalls using a dynamic linked library then it should be fine. To verify this please perform a web lookup on some topic like "Qt QSocket compatibility with ACE".

Is there any dynamic memory allocation (new, delete)?

Yes, dynamic allocations are used extensively in qmqtt and over all parts of Qt in general.

Does the library have threading model or single thread execution?

qmqtt works on behalf of Qt's asynchronous QEventLoop approach. There should be no internal threads created under the hood.

How are the exception handled? (Exception handling should not throw and end execution)

The library should not throw any exceptions since they are not Qt-standard. To get error cases you need to connect the error signals to some sort of handler ("slot" in Qt jargon).