[TOC]
This project is built using Nameko, a microservices framework for Python that lets you focus on writing your services without needing to worry about the underlying infrastructure. Our services communicate through a mix of HTTP and RPC, and we compare synchronous and asynchronous operations, as well as Redis and MySQL databases.
These instructions will get you a copy of the project up and running on your local machine for development and testing purposes.
Before you start, ensure you have the following installed:
- Python 3.x
- Docker (optional, for running services in containers)
- RabbitMQ (Nameko uses RabbitMQ for service communication)
Follow these steps to get your development environment running:
-
Clone the repository to your local machine:
git clone https://github.com/KaitaoQiu/microservice_experiment.git
-
Navigate to the project directory:
cd microservice_experiment
-
Install the required dependencies:
pip install nameko, redis, mysql, aiomysql
-
Ensure RabbitMQ is running.
If you're using Docker, you can run:
docker run -d -p 5672:5672 rabbitmq
To run your Nameko service, use the nameko run
command followed by your service module name. For example:
nameko run sync_service_y
Replace sync_service_y
with the Python module where your service is defined.
This project uses pytest for testing. Test files are located in the test_misc
directory.
To run the tests, navigate to the root of the project and execute:
cd test_misc
# for example, you want to add data into redis
python redis_add_random_data.py
# then, you can run cprofile to test cpu time and latency
python redis_cprofile_test.py
This will discover and run all the test cases defined in the test_misc
directory.
- HTTP Requests: Our services use HTTP GET requests to query data from the customer table in a MySQL database. The response is returned in JSON format.
- RPC Microservice: We have a synchronous RPC microservice that interacts with a MySQL database. This service is used to compare its response with that of the HTTP service to ensure data consistency and integrity.
- Synchronous Services: We have a synchronous service (Service X) that reads data from an SQL database. This service is called by another synchronous service (Service Y) to process the data.
- Asynchronous Services: Asynchronous Service X establishes a connection to the aiomysql database. Asynchronous Service Y calls this service to process the data. We compare the processing times of synchronous and asynchronous operations to optimize our data handling.
- Database Comparison: Our synchronized service reads from two different databases, Redis and MySQL, to compare their performance and suitability for different types of data and operations within our microservices architecture.
- Nameko - The microservices framework used
- RabbitMQ - Messaging broker
- Redis - In-memory data structure store, used as a database
- MySQL - Open-source relational database management system
This project is licensed under the MIT License - see the LICENSE file for details.