This post wrap up a hello-world demo for django Microservices web app, and shold serve well as a template.
First, What is Pattern: Microservices Architecture:
refer below from http://microservices.io/patterns/microservices.html
Context You are developing a server-side enterprise application. It must support a variety of different clients including desktop browsers, mobile browsers and native mobile applications. The application might also expose an API for 3rd parties to consume. It might also integrate with other applications via either web services or a message broker. The application handles requests (HTTP requests and messages) by executing business logic; accessing a database; exchanging messages with other systems; and returning a HTML/JSON/XML response.
The application has either a layered or hexagonal architecture and consists of different types of components:
Presentation components - responsible for handling HTTP requests and responding with either HTML or JSON/XML (for web services APIS) Business logic - the application’s business logic Database access logic - data access objects responsible for access the database Application integration logic - messaging layer, e.g. based on Spring integration. There are logical components corresponding to different functional areas of the application.
The motivations are :
There is a team of developers working on the application New team members must quickly become productive The application must be easy to understand and modify You want to practice continuous deployment of the application You must run multiple copies of the application on multiple machines in order to satisfy scalability and availability requirements You want to take advantage of emerging technologies (frameworks, programming languages, etc)
So what is Microservice Architecture:
Reference ends here. Now start my demo code. Below is how I plan to do it:
Tier one app. It’s an empty app, only has Settings.py and url.py is important. You start your whole application by bootstraping this app python manage.py runserver from here.
1 2 3 4 5 6 7 8 9 10
1 2 3 4 5 6 7 8 9
Now go to another tier one app, tbcheck. This app serves as view app, with all template, tamplate tag, css stuff there url.py
1 2 3 4
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
At last is tier two app. tbmodel
Only has models.py in it. It is just another package.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
now when we run it, we first pip install all view, model app as package to site-package places. Then bootstrap the first app to start.
To access code and see hello world in 5 sec, just go to this link: