In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
In this issue, the editor will bring you about how to practice the selection of micro-service architecture. The article is rich in content and analyzes and describes it from a professional point of view. I hope you can get something after reading this article.
Design
System architecture
Micro service development architecture. PNG
Only need a set of BASE micro-services, BASE micro-services generate business system micro-service instances for each business system to call; business systems do not directly call BASE, can only call micro-service INSTANCE.
Question 1: some people will ask, if there are 20 business systems, there are hundreds of micro-services, how can this be managed?
-- this is the problem of operation and maintenance, which can be solved by operation and maintenance. It is not difficult for operation and maintenance to use tools. Anyway, they are all scripts and do not need to be operated manually.
Question 2: why not build a saas microservice so that there are less than 10 microservices, which is very easy to manage, isn't it?
-- A single point of failure affects the overall situation, and we choose stability is more important; in addition, in the case of saas, in order to deal with different industries, there will be suspicion of over-design; privatization is easier.
Calling logic
Call logic .png
The client invokes the business system and does not invoke the micro-service directly.
There is also an invocation relationship within the microservice.
Design concept
Modularization is the foundation
Non-modular, not to mention micro-services, such as user micro-services, product micro-services, address micro-services, and so on, all need to be modularized first. In order to better implement the development, you may have to, while modularizing, micro-services. When modularization, you should pay attention to the fact that there can be no related queries, and the packages must be completely independent before the micro-services can be opened.
Micro-service while modularization. PNG
Loose coupling and strong cohesion
Loose coupling means that our modules are not directly dependent, stateless, and can provide services to the outside world alone.
Strong cohesion means that although we have to split into small micro-services, we also have to consider the strong relevance of some functions. For example, a stool is made up of four feet and a board, and we cannot sell the four feet separately from the board. It makes no sense.
Development
Strong and friendly spring system
Java development for more than 5 years is very clear, many JAVA frameworks have faded out of sight, such as hibernate, struts1, struts2, only spring is becoming more and more popular.
Spring-boot: more simple than springmvc, springmvc has a large zero configuration files, such as spring-servlet, spring-mybatis, spring.xml and web.xml, which are not needed in spring-boot, only powerful annotation capabilities are needed. Boot is more suitable for micro services.
Spring-cloud: there are many components to support micro-services, such as spring cloud config Unified configuration Center, for configuration of configuration files in multiple environments, so that people no longer have to worry about the development, testing and production of multiple micro-services. Spring cloud eureka is used for service registration and discovery, which is described separately below. You can go to the official website to have a look at other components, which will not be introduced here. In short, if you are on the JAVA platform, try to use the content of the spring system.
Database
We use mysql because we have many applications, but the data volume table is not large, and the data quantity table is not more than one million. Mongodb has also been tested, and the development is very fast and flexible, but because it is not a relational database, the maintenance cost is high.
Authority authentication
For external verification, internal full trust mechanism.
Permission authentication .png
Interface specification
RESTFUL:URL 's resources and operation are decoupled, making URL more semantic, and hundreds of interfaces are also very easy to manage. There are many articles on the Internet that are very thorough. It is not very easy to understand. If you practice in a project, you will feel like a spear and shield. I will not elaborate on it here.
Interface document swagger: compared with the traditional manual interface document, swagger has a unified output format, no matter how many people write it. Swagger uses to write code to write interface documents, previously modified the code, but also must open wiki manually modify the interface document, now only need to modify the code, programmers are more willing to modify, the cost is lower, the front end and other callers will not roar every day, you this interface how to change, what does the newly added field mean?
Service Registration and Discovery spring cloud eureka
After the service interface is changed, you no longer need to verbally notify the service caller, because there are so many callers that you have no idea who he is, so you will inevitably miss it. PHP can be supported.
Service registration discovery .png
Message queue
RocketMQ: has been struggling with kafka and rocketMQ, and finally chose RocketMQ. Here is a detailed description of http://www.jianshu.com/p/453c6e7ff81c.
Asynchronous programming mode
For performance considerations, try to use asynchronous programming, such as registering to send coupons, then successful registration can return to the user that the registration is successful, but coupons can be invoked asynchronously without blocking the registered thread.
Real-time log analysis platform ELK
Under the micro-service framework, logs can not be scattered on each service node, there must be a unified log center. ELK is a real-time log analysis platform, which aggregates the logs of each service in the log center, and then searches according to system, node, etc. In addition to the above search conditions, we also implement search logs based on business id (generate one business id per request) and user id in each microservice to facilitate tracking and locating problems.
Unified configuration Center ETCD
Of course, there may be more lightweight and easy-to-use disconf or spring cloud config, but we have applications developed by php, neither of which is supported. If they are all JAVA applications, it would be nice to use disconf.
test
Microservice interface testing tool postman
Every programmer has such an experience. As soon as we go online, the customer gives feedback to bug. It turns out that when we modify some functional code, it leads to the bug of other functions, which is uncertain every time we go online. This reflects the necessity of interface testing, especially when each version is upgraded, it needs to be executed again to prevent modification of an interface causing other interfaces to report errors, which is much more reliable than manual testing.
Deployment
A good friend of micro-service: docker
Docker is already a household name, and this is another major change after the virtual machine, putting all the individual micro services in the docker, so that when and where you want to deploy, you can just throw it into the OK.
A powerful tool for load balancing: docker swarm
With a few simple commands to get the load balancing done, but also can be smoothly upgraded, version upgrade, we do not have to tell customers: system notice, some night at 00:00-08:00 our bank is in the process of system upgrade and maintenance, everyone do not go to withdraw money, because you may not be able to take it out, hehe.
Upgrade
Database upgrade
Make a physical or logical backup of the database before upgrading
Database scripts cannot contain statements that delete or modify tables and data to prevent old business from reporting errors during the upgrade process.
Before all scripts go online, the operation and maintenance staff must check, some sensitive words drop or delete
We use the tool flyway to version control the database scripts.
Continuous integration
Traditional version upgrade, 1. Develop push code and record which files you submitted at the same time; 2. The project manager examines the documents according to svn and packages them into war packages. Put it into the test environment for the test company to test; 4. If I changed the file halfway, I may need to repackage it; I can't write any more, and the project manager is like Superman.
Now using continuous integration (CI) is very simple, we use the tool is Jenkins, push the code, click a few buttons to complete the launch, whether it is the test environment or production environment is very simple, otherwise the project manager to check the file eyes are green.
This is how to practice the micro-service architecture selection shared by the editor. If you happen to have similar doubts, you might as well refer to the above analysis to understand. If you want to know more about it, you are welcome to follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.