Three microservices used to demonstrte setting up Citus as scalable storage backend for microservices.
SET citus.enable_schema_based_sharding TO ON;
CREATE SCHEMA AUTHORIZATION user_service;
CREATE SCHEMA AUTHORIZATION time_service;
CREATE SCHEMA AUTHORIZATION ping_service;
Execute the corresponding SQL file as every service.
psql -U user_service -f user_service/user.sql
psql -U time_service -f time_service/time.sql
psql -U ping_service -f ping_service/ping.sql
Modify the db_config
variable for every service in their app.py
.
db_config = {
'host': 'localhost',
'database': 'citus',
'user': 'time_service',
'port': 9700
}
Change into every app directory and run them in their own python env.
cd user
pipenv install
pipenv shell
python app.py
Repeat the above for time
and ping
service.
# Create 10 users
curl -X POST -H "Content-Type: application/json" -d '[
{"name": "John Doe", "email": "[email protected]"},
{"name": "Jane Smith", "email": "[email protected]"},
{"name": "Mike Johnson", "email": "[email protected]"},
{"name": "Emily Davis", "email": "[email protected]"},
{"name": "David Wilson", "email": "[email protected]"},
{"name": "Sarah Thompson", "email": "[email protected]"},
{"name": "Alex Miller", "email": "[email protected]"},
{"name": "Olivia Anderson", "email": "[email protected]"},
{"name": "Daniel Martin", "email": "[email protected]"},
{"name": "Sophia White", "email": "[email protected]"}
]' http://localhost:5000/users
# List users
curl http://localhost:5000/users
# Get current time
curl http://localhost:5001/current_time
# Ping example.com
curl -X POST -H "Content-Type: application/json" -d '{"host": "example.com"}' http://localhost:5002/ping
Copyright (c) 2023, Microsoft
Licensed under the MIT license - feel free to incorporate the code in your own projects!