MicroServices Architecture Practices-do you know that Docker and spring boot are enough?

Source: Internet
Author: User
Tags docker swarm etcd


MicroServices Architecture Practices-do you know that Docker and spring boot are enough?author of cloud Hair has been concerned about 2017.02.27 02:50* words 2613 Read 2583 comments 6 likes 2

MicroServices do not exist alone, in order to better implement the micro-service architecture, the need to integrate many components mix-and-match use, can open the two-channel, invincible. Many danale on the web spoke about the content of micro-service governance, there are also some unilateral micro-services, such as spring boot and Docker, this article focuses on the selection of components of the contest, but also accumulated a number of our team PK essence; These components include spring boot, Spring cloud, Docker, Service registration discovery, RESTFUL, Postman, Jenkins, ELK, Etcd, and more.

Background


With the company more than a year of growth, we have developed dozens of projects, the background of Java has PHP, in order to better improve the development and management efficiency, the technology of the cattle are often fierce PK, the collision of many sparks of love, such as one of them: micro-service Practice


Design System Architecture
Micro-service development architecture. png


Just a set of base microservices, base microservices generate business system microservices instances for each business system call; The business system does not call base directly, only the MicroServices instance can be invoked.



Question one: Some people will ask, if there are 20 business systems, there are hundreds of micro-services, how to manage it?
----This is the operation and maintenance of the problem, let operations to solve, operation and maintenance of tools, the actual is not difficult, anyway, the execution is a script, do not need manual operation.



Question two: Why not make a SaaS micro-service, so that only less than 10 micro-services, it is very easy to manage it?
----single point of failure affects the overall, we choose stability more important; In addition to SaaS, there is a suspicion of over-design in order to deal with different industries; privatization is easier.


Call logic
Call logic. png
    • The client invokes the business system and does not invoke the microservices directly;
    • There is also a call relationship inside a microservices service.
Design concept
    • Modularity is the basis of


Non-modular, not much micro-services, such as the above user micro-services, product microservices, address micro services, etc., need to be modular, in order to better implement the development, you may have to, the side of the modular edge of micro-services, modular time to note, can not have related queries, package to completely independent, then micro-service can be opened



Edge Modular Edge Micro service. png
    • Loose coupling, strong cohesion


Loosely coupled means that our modules are not directly dependent, stateless and can provide services to the outside world individually;



Changnezu means that although we want to split into small micro-services, but also to consider the strong correlation of certain functions, such as a stool is composed of four feet and a board, we can not put four feet and the board sold separately, there is no point.


Develop a strong and friendly spring system


Java development More than 5 years are very clear, many Java frameworks have faded out of view, 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 file, such as Spring-servlet, Spring-mybatis, Spring.xml and Web. XML, these are not needed in spring-boot, only need a powerful annotation function, boot more suitable for micro-services.



Spring-cloud: There are more components to support microservices, such as the Spring Cloud Config Unified Configuration Center, for multi-environment configuration file configuration, you can no longer for the development of multiple microservices, testing and production environment profile management and worry about it; spring Cloud Eureka for service registration and discovery, the following are separately introduced, other components can go to the official website to see, here is not introduced, in short, if the Java platform, as far as possible to use the content of the spring system.


Database


We use MySQL, because we are the application of many, but the data volume single table is not large, more than million, MongoDB has also experimented, development is very fast, but also very flexible, but because it is not a relational database, maintenance costs are high.


Authority authentication


For external validation, the internal full trust mechanism.



Permission authentication-PNG Interface specification


Restful:url Resources and operations decoupling, so that URLs more in line with the semantics, hundreds of interfaces are also very good management, there are many articles on the Internet very thorough, this thing is not particularly good understanding, to learn more, in the project practice, there is a spear plug shield to open the feeling, here do not do a detailed introduction.



Interface document Swagger: Compared to the traditional full manual interface document, swagger has a unified output format, no matter how many people write, swagger write code to write the interface document, previously modified the code, you must also open the wiki to manually modify the interface document, Now only need to modify the code, the programmer is more willing to modify, the cost is lower, the front end and other callers will not roar every day, you this interface why change, the new addition of the field is what meaning ah.


Service registration and Discovery Spring Cloud Eureka


After the service interface changes, there is no need to verbally notify the service caller, because the caller is too many, you do not know who he is, inevitably omitted; Support PHP.



Service registration discovery. PNG Message Queuing


ROCKETMQ: Has been tangled Kafka and ROCKETMQ, the final choice ROCKETMQ, here are details about HTTP://WWW.JIANSHU.COM/P/453C6E7FF81C


Asynchronous Programming methods


For performance above considerations, try to use asynchronous programming, such as registration to send coupons, then the successful registration can be returned to the user registration is successful, but the coupon can be called asynchronously, do not block the registered thread.


Real-time log analysis platform ELK


Under the micro-service framework, the log cannot be scattered across the service nodes and must have a unified log center. Elk is a real-time log analysis platform, is to summarize the logs of each service in the log center, and then can follow the system, nodes and other search, in addition to the above search conditions, we also implemented in each micro-service according to the business ID (one request to generate a business ID) and user ID search log, easy to track and locate the problem.


Unified Configuration Center ETCD


There may be more lightweight and easy-to-use disconf or Spring Cloud Config, but we have PHP-developed apps, none of which is supported. If all Java applications, the use of disconf is still very good.


Test micro-service Interface test Tool postman


Every programmer has this experience, just on-line, the customer feedback the bug, the original is that we modify a function code, resulting in other features of the bug, every time on the line of the heart is not the end; This reflects the need for interface testing, especially every version of the upgrade, it is necessary In case the modification of an interface causes other interfaces to error, it is much more reliable than manual testing.


A good base for deploying MicroServices: Docker


Docker has become a household name, and this is a major change after the virtual machine, to put all the individual microservices in Docker, so when and where you want to deploy, just drop the past is OK, fast to explode.


Load balancing weapon: Docker swarm


With a few simple commands to take care of the load balancer, but also can be smooth upgrade, the version of the upgrade, we do not have to tell customers: System notice, a certain night 00:00-08:00 I line in the system upgrade maintenance, we do not go to fetch money oh, because you may not come 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, preventing old business errors during upgrade
    • All scripts on-line before OPS must check, some sensitive words drop or delete


We use the tool Flyway, which allows versioning of database scripts.


Continuous integration


Traditional version upgrades, 1. Develop push code and record which files you submitted at the same time; 2. Project manager according to SVN audit files, and packaged into a war package; 3. Put the test company to test environment, 4. Modify the file in the middle, it may need to be repackaged; I can't write anymore, the project manager is like a Superman.



Now with continuous integration (CI) is very simple, we use the tool is Jenkins, push through the code, a few buttons to complete the online, whether it is a test environment, or the production environment is very simple, or the project manager check the file eyes are green.


End of last note


This article is mainly to introduce the micro-service development on the selection, for the details do not do a deep dive, we are interested to understand the next components. Of course, our selection is correct, different scenarios may be completely different application, this article is for reference only.


Their own growth


Xiaixiaoquan's CTO Jerry, let me see the height of Hw technology, whether it is the vision or the details, have completely conquered me, although I have also worked as a listed company, service banking, securities industry; Let me feel that hw is a regular army, we are bandits, although all can win the battle, but others slogan louder, more routine In addition, the power of Xiaixiaoquan information team makes each of us grow rapidly.


Reading and writing


Recently more obsessed with reading and writing, no attitude, not long text, the back will continue to launch some of the experience summed up the article, Welcome to Exchange learning with each other.



MicroServices Architecture Practices-do you know that Docker and spring boot are enough?


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.