Simple Microservices with django rest framework, Celery and RabbitMQ
- Python 3.4+
- Django 1.8+
- Django-REST-Framework 3.0+
- RabbitMQ 3.6+
- Celery
- Redis
- Django-REST-Framework-JWT
Install RabbitMQ via the this link
please refer to the installation instructions for your specific platform
and Get RabbitMQ running in the background with:
$ sudo rabbitmq-server
Install Redis via the this link
Run the Redis server from a new terminal window:
$ redis-server
Create a new virtualenv:
$ virtualenv reward_env
$ source reward_env/bin/activate
In the root directory of the project, run below command in the terminal:
pip install -r requirements.txt
A Simple SSO server that handles Authentication and Authorization (JWT)
we need to create our tables in the database, to do that, run the following command:
$ python manage.py migrate
start the development server:
$ python manage.py runserver
finally running the Celery worker server(adding dynamic data to the order items in other services):
$ celery -A admin_tasks worker --loglevel=info
The McDonald and the Uber Project is the same project with different name (for demonstration purposes only):
postgres requirement:
user=python_user
password=^uCd*r7-M$
database=mcdonald_db
create the tables with:
$ python manage.py migrate
start the development server(port=8001):
$ python manage.py runserver 8001
finally running the Celery worker server(adding dynamic data to the order items in other services): the celery worker just handles tasks in the mcdonald queue
$ celery -A mcdonald_tasks worker --loglevel=info -Q mcdonald
postgres requirement:
user=python_user
password=^uCd*r7-M$
database=uber_db
create the tables with:
$ python manage.py migrate
start the development server(port=8002):
$ python manage.py runserver 8002
finally running the Celery worker server(adding dynamic data to the order items in other services): the celery worker just handles tasks in the uber queue
$ celery -A uber_tasks worker --loglevel=info -Q uber
For every operation, you need a token
first of all you must register a user
SignUp
Method: POST
data: {
'username': 'any-name',
'password': 'password'
}
SignIn
get a token
http://127.0.0.1:8000/api-token-auth
Method: POST
data: {
'username': 'any-name',
'password': 'password'
}
Get All Valid Clients
uber or mcdonald
http://127.0.0.1:8000/clients/
Method: GET
Authorization: JWT token
Add or Update order items attributes(Admin panel)
add or update order items attribute in other services(uber or mcdonald)
http://127.0.0.1:8000/clients/
Method: POST
Authorization: JWT token
data: {
client: uber|mcdonald,
key1: value1,
key2: value2,
...
}
Post data to a service
http://127.0.0.1:8002/api/orders/
Method: POST
Authorization: JWT token
data:{
key1: value1,
key2: value2,
key3: value3,
...
}
Update a record
http://127.0.0.1:8002/api/orders/
Method: PUT
Authorization: JWT token
data:{
key1: value1,
key2: value2,
key3: value3,
...
}
Delete a record
http://127.0.0.1:8002/api/orders/id
Method: DELETE
Authorization: JWT token
Get a record
http://127.0.0.1:8002/api/orders/id
Method: GET
Authorization: JWT token
Each user can only do 5 unsafe method operation(Add, Edit, Delete) per minute
All transactions are logged