This is a distributed message broker system that follows the Publisher-Subscriber design pattern. It is implemented in Python and consists of three main components:
- Message Broker (server.py)
- Publisher (publisher.py)
- Subscriber (subscriber.py)
- Publishers can register themselves with the message broker and publish messages to specific topics.
- Subscribers can register themselves with the message broker and subscribe to specific topics of interest.
- The message broker handles the distribution of messages from publishers to subscribers based on their subscriptions.
- The system supports multiple publishers and subscribers, allowing for a distributed and scalable architecture.
- The message broker ensures that messages are delivered to all subscribers of a topic.
- Subscribers can pull new messages from the message broker for the topics they are subscribed to.
- Python 3.x
- Install required dependencies (if any, e.g., asyncio or other libraries).
- Clone the repository:
Running the Message Broker (Server) Start the message broker (server) by running the server.py file:
python3 server.pyThis starts the message broker on localhost:5555 by default. The server will listen for connections from both publishers and subscribers. You should see the following output, indicating the server is running:
Server started on localhost:5555
- Open a new terminal window.
- Run the publisher.py script:
python3 publisher.py --create my_topic- This command creates a new topic named my_topic and registers the publisher.
- To publish a message to the my_topic topic:
python3 publisher.py --publish my_topic "Hello, world!"-
You should see confirmation that the message was successfully sent. Additional commands for the publisher include:
-
Create a topic:
python3 publisher.py --create my_topic -
Send a message:
python3 publisher.py --publish my_topic "Your message here" -
Delete a topic:
python3 publisher.py --delete my_topic -
Register as a publisher using the
registerPublisher()function. -
Create topics using the
createTopic(topic)function. -
Publish messages to a topic using the
send(topic, message)function. -
Delete topics using the
deleteTopic(topic)function.
- Run the subscriber.py script to subscribe to a topic:
python3 subscriber.py --subscribe my_topic-
Register as a subscriber using the
registerSubscriber()function. -
Subscribe to topics of interest using the
subscribe(topic)function. -
Pull new messages from subscribed topics using the
pull(topic)function. -
The message broker listens on
localhostand port5555by default. You can modify these settings in theserver.pyfile.
- Inline code comments are provided to explain the functionality of each component.
-
To run performance benchmarks for the message broker, use the provided benchmarking scripts. For example:
-
Run the createTopic benchmark:
python3 benchmark_createTopic.pyRun the send message benchmark:
python3 benchmark_send.py- These scripts will simulate multiple clients and measure throughput for different operations. Detailed results will be printed to the console
Contributions are welcome! If you find any issues or have suggestions for improvements, please open an issue or submit a pull request.
This project is licensed under the MIT License.
For any questions or inquiries, please contact [email protected].