This is a message retrieval and posting system implemented in C. Implementation is done similar to MQTT protocol which is a common protocol used for IoT applications.
-
Components -
- Broker - Server for storage of messages posted by the publisher. There have to be a minimum of 2 brokers connect to eachother in a circular network. Messages can be posted to any of the brokers and retrieved from any other. Every Broker on the system has a unique
broker_idthat it uses to identify itself. - Publisher - client that provides interface to post messages to the broker. It has interface to create a topic on the broker. Messages are published under a topic.
- Subscriber - client that provides interface to read messages from the brokers. Any subscriber first has to subscribe to a topic before reading any messages under it.
- Broker - Server for storage of messages posted by the publisher. There have to be a minimum of 2 brokers connect to eachother in a circular network. Messages can be posted to any of the brokers and retrieved from any other. Every Broker on the system has a unique
-
General Struct Definition -
typedef struct my_struct{
int type;
char message[512];
char topic_name[50];
int msg_id;
int client_id;
int broker_id;
}master;
Any communication between Broker, Publisher and Subscriber is done using the above struct
- Setup (for network of 2 brokers)
- Compile and run
first_broker.cand enter theLISTEN_PORT. - Compile and run
broker.cin another folder and inputIP_ADDRESSandLISTEN_PORTof thefirst_brokeras CLA, also assignLISTEN_PORTfor the second broker. - Enter the
IP_ADDRESSandLISTEN_PORTthat you assigned to second broker in thefirst_broker. - Circular network of 2 broker has been established.
- Compile and run
publisher.cand enter theIP_ADDRESSandLISTEN_PORTof the any one of the brokers and follow the interface to publish a message.