We have a requirement where we wish to run broker and subscriber in same process.
Sould we try to tweak broker source, create a shared libraray and link with subscriber process?
Woult it work ? Any chances of conflict or run time issues ?
What other approaches you can suggest to run broker and subscriber in same process?
What do you actually want to achieve with the subscriber? You could potentially create a broker plugin that uses the “message in” event to consume the messages you are interested in.
Cheers,
Roger
We are trying to create a multithreaded application, in which one thread will launch broker and other threads will launch publisher and subscriber.
There will other pub-sub processes as well on Linux box.
So we tried to tweak broker source, create a shared library and link with subscriber process. But at run time things did not work. are there any predeclared constraints while trying to run broker and client in same process ?
Hi,
if your subscriber code is based on the libmosquitto this might bring you into some problems. As the mosquitto broker implementation is reusing some of source files and functions of the libmosquitto. But the broker is compiling these files with different configs and defines (e.g grep for a WITH_BROKER in the source lib folder). So putting the broker into a shared library as well you will end up with two different shared objects with overlapping symbols. But the symbols referencing structs may have different object sizes. This may end up quite badly, depending on which symbols the linker/load finds first.
The easiest way to solve your requirements might be to use the existing broker binary and implement a plugin based on the plugin API as roger propose above. You will have to use the develop branch for now and compile the broker from source as the extended API is not available on the master branch right now. If you register for a MESSAGE_IN event you will get your callback invoked for each incoming message.