I have four mqtt client which two of gonna be connect together and two others connect together. For example Client A publish data to client B on topic /AtoB and client X publish data to client Y on topic /XtoY. now I am going to route this two topic on a mqtt broker on my PC. How I should setup my broker? and Also I found mqtt libraries for mqtt client but I didn't found(is it possible?) library to write a mqtt broker. thanks
1 Answers
MQTT is a pub/sub protocol and as such designed to totally decouple the publisher from the subscriber.
This means that a publishing client doesn't need to care about what (or how many) clients may be subscribed to a topic (removing any need for "routing").
In the example you gave, Client A publishes to topic AtoB
* Client B will subscribe to that topic. Likewise Client X publishes to topic XtoY
and Client Y subscribes. If an app on your PC wants to receive the same messages then it would also subscribe to both topics AtoB
and XtoY
and would receive the same messages.
The second question part of your question about libraries. Normally there would be no need to use a library to create a broker, just use one of the existing brokers. If you REALLY REALLY need to do something none standard then there are libraries like mosca to implement custom brokers.
*topics do not need to start with a /
and doing so adds an extra layer of complexity best avoided.