Traditional Culture Encyclopedia - Traditional festivals - Practice of Microservice Architecture-Do you only know docker and spring boot?
Practice of Microservice Architecture-Do you only know docker and spring boot?
With the growth of the company for more than a year, we have developed dozens of projects with JAVA and PHP in the background. In order to better improve the efficiency of development and management, technology bulls and calves often have fierce PK, and many sparks of love collide, such as one of them: micro-service practice.
design
Only one set of basic microservices is needed, and the basic microservices generate microservice instances of business systems for each business system to call; The business system does not call BASE directly, but can only call microservice instances.
This is a problem of operation and maintenance, which is solved. It is not difficult to use tools in operation and maintenance. Anyway, all scripts are executed without manual operation.
Single point failure affects the whole situation, so we choose stability is more important; In addition, saas, in order to cope with different industries, will be suspected of over-design; Privatization is easier.
Call logic
design concept
Non-modular, not to mention micro-services, such as user micro-services, product micro-services, address micro-services, etc. All of the above need to be modularized first. In order to achieve better development, you may need modular microservices. When modularizing, it should be noted that there can be no related queries, and the package must be completely independent before the microservice can be disassembled.
Loose coupling means that our module is not directly dependent and stateless, and can provide services to the outside world independently;
Strong cohesion means that although it should be split into small and micro services, it should also consider the strong correlation of some functions. For example, a stool is composed of four feet and a board. If you can't sell the four feet and a board separately, it's meaningless.
exploit
Spring-boot: Compared with springmvc, the configuration file of springmvc is zero, and spring-servlet, spring-mybatis, spring.xml, web.xml, etc. are not needed in spring-boot, only powerful annotation function is needed. Boot is more suitable for microservices.
Spring-cloud: There are many components supporting microservices, such as spring cloud config Unified Configuration Center, which is used to configure configuration files in various environments. You no longer have to worry about the development, testing and configuration file management of multiple microservices. Spring cloud eureka is used for service registration and discovery, which is introduced separately below. You can go to official website to see other components. I won't introduce it here. In short, if it is a JAVA platform, try to use the content of spring system.
We use mysql because we have many applications, but the data tables are not large, and most of them are less than one million. Mongodb has also done experiments, which are very fast and flexible, but because it is not a relational database, the maintenance cost is high.
Restful: The resources and operations of URL are decoupled, which makes URL more semantic and hundreds of interfaces are very easy to manage. There are many articles on the internet that are very thorough. This thing is not particularly easy to understand. If you want to know more, you will feel that the project is blocked by a spear. I won't introduce it in detail here.
Interface document swagger: Compared with traditional manual interface documents, swagger has a unified output format, no matter how many people write it; Swagger writes interface documents by writing code. To modify the code before, you need to open the wiki to manually modify the interface document. Now, you just need to modify the code. Programmers are more willing to modify and the cost is lower. Front-end and other callers don't shout every day. Why has your interface changed again? What do you mean by adding a new field?
RocketMQ: I have been obsessed with Kafka and rocketMQ, and finally chose RocketMQ.
For the sake of performance, try to use asynchronous programming, such as sending coupons after registration, then the successful registration can be returned to the user, but sending coupons can be called asynchronously without blocking the registration thread.
Under the framework of micro-service, it is impossible for logs to be scattered on all service nodes, and there must be a unified log center. ELK is a real-time log analysis platform, which collects logs of various services in the log center, and then can search by system, node and so on. In addition to the above search conditions, we also realize the log search according to the service id (one service id is generated at a time) and user id in various micro-services, which is convenient for tracking and positioning problems.
Of course, there may be a lighter and easier-to-use disconf or spring cloud config, but we have applications developed by php, and neither of them is supported. If it's all JAVA applications, it's still very good to use disconf.
test
Every programmer has this experience. When he first went online, the customer gave back a bug. It turns out that we modify a function code, which leads to bugs in other functions, and we have no bottom every time we go online. This reflects the necessity of interface testing, especially every version upgrade, to prevent the modification of one interface from causing other interfaces to report errors, which is much more reliable than manual testing.
deploy
Docker has become a household name, which is another major change after the virtual machine. All the individual micro-services are put in docker, so that when you want to deploy them anywhere, just throw them and they will explode.
With a few simple commands, you can achieve load balancing and upgrade smoothly. You don't need to tell the customer when upgrading the version: the system will inform us that our bank will upgrade and maintain the system from 00: 00 to 08: 00, so don't withdraw money, because it may not be available, hehe.
promote
We use the tool flyway to control the version of the database script.
Traditional version upgrade,
1. Develop push code to record which files you submitted at the same time;
2. The project manager packages it into a war package according to the svn audit file;
3. Put it into the test environment for the test company to test;
4. The file was modified in the middle and may need to be repackaged;
….
I can't write anymore. The project manager is like a superman.
It is very simple to use continuous integration (CI) now. The tool we use is Jenkins. After pushing the code, we can go online with a few buttons. Both the test environment and the production environment are very simple, otherwise the project manager's eyes will be green when checking the documents.
final result
This paper mainly introduces the choice of micro-service development, without going into details. If you are interested, you can learn about each component. Of course, our choice is correct, and different scenes may be completely different. This article is for reference only.
- Previous article:What kind of food can radish be made into?
- Next article:Seeking a traditional infinite flow novel is basically similar to horror.
- Related articles
- Tobacco two-dimensional code query authenticity query system
- China's traditional philosophy ppt
- Why are traditional health exercises so popular with young people?
- How to install sliding door locks correctly? Make your private space more secure
- The sense of ceremony of chopsticks, the culture of China.
- What are the requirements for opening a calligraphy training class?
- What does it mean to tie the middle finger with a red rope?
- Presided over the Spring Festival get-together.
- How far was the bow and arrow used in ancient wars?
- How to eliminate vomiting symptoms in advanced thyroid cancer?