Thread Previous • Date Previous • Date Next • Thread Next |
Hi Roger,Thanks for your example, it gave me helpful clues to improve my code elsewhere.
I totally agree with you, it depends on the requirements. Maybe it is better to state my requirements more precisely: In your example your client's publish depends on the "on_message event". In my client publish and subscribe should be independent of each other but they should share the same loop-method (in other words, the same connection to the broker). The client should listen on its socket for inbound messages but the listener should not halt the whole program. If a message arrives, my on_message-callback-function transfers this message to an external message-handler object, which interprets the content and does further processing, but this is not relevant for the client. And finally, an external event (function call) should always be able to trigger a publish.
A pattern would be the IA91 Java client provided by IBM. The client connects to the broker, topics can be subscribed and while the client is publishing messages other messages from the broker can be received.
So, my client should only be responsible for receiving and sending messages but it should be able to do both at the same time. External modules can trigger a publish by calling the client's publish-method (together with a reference to a message-object) and inbound messages get transferred to another module, let's call it MessageHandler. And for the final step of the project it is necessary to run the whole client in at least one thread independent from the main process. Because my client is only a smaller part of a project und should not affect the other modules. Therefore an exclusive usage of the main() isn't possible.
I know this is not a very technical description, but rather a first approach to summarize the functionallity in writing. Please tell me, if something needs further explanation (perhaps with UML).
Rene Am 05.03.2012 10:42, schrieb Roger Light:
Hi Rene, How you create a client that does both publish and subscribe really depends on what you need to achieve. I've created a simple C++ example that does both publish and subscribe. It subscribes to a celsius temperature feed, converts the temperature into farenheit and republishes the same data. You can see this example at https://bitbucket.org/oojah/mosquitto/src/d22f87ef34f0/examples/temperature_conversion Cheers, Roger On Sat, Mar 3, 2012 at 1:49 PM, Rene Lösch<rene.loesch@xxxxxx> wrote:Hello, I'm looking for some help building a MQTT client which combines both, subscription-functionality and publish-functionality. I'm using the mosquitto C++ wrapper for mosquitto lib and I have already a prototype which is able to do that. The client-loop-method together with the do-while-loop is processed by a separated thread, but I'm unsure if that is the right way. My only clues are Roger's sources for a single pub_client and sub_client written in C. Does someone have a "construction manual" for me or provide a small setp-by-step guide how to build such a client? Any advice on ways how to combine these functionalities is welcome, also for language C. Thanks, Rene _______________________________________________ Mailing list: https://launchpad.net/~mqtt-users Post to : mqtt-users@xxxxxxxxxxxxxxxxxxx Unsubscribe : https://launchpad.net/~mqtt-users More help : https://help.launchpad.net/ListHelp_______________________________________________ Mailing list: https://launchpad.net/~mqtt-users Post to : mqtt-users@xxxxxxxxxxxxxxxxxxx Unsubscribe : https://launchpad.net/~mqtt-users More help : https://help.launchpad.net/ListHelp
Thread Previous • Date Previous • Date Next • Thread Next |