Java-SpringBoot and SpringCloud Microservices-Basic Introduction

SpringBoot automatic configuration, dependency injection

SpringBoot solves Java's management of third-party packages through automatic configuration and dependency injection, which reduces the coupling of class interdependence.

configuration

SpringBoot is based on convention and has many default configuration values. If you need to modify it, you must use the agreed name and write the value you want to set.
application.properties:

server.port=8080

application.yml/application.yaml:

server:
  port: 8080

When all three configuration files exist, the settings in properties take the highest priority

Spring Cloud Microservices

Advantages and disadvantages

  • Flexible single deployment, each service application is deployed independently, low coupling, can easily complete distributed and increase or decrease services
  • Reduce startup difficulty and downtime hazards
  • Different project technologies are optional. Compared with a single application project, it can almost only be relocated to a new technology stack as a whole, and the huge amount of code is time-consuming and labor-intensive. There may not be a perfect compatible implementation. Different service projects in microservices can allow the use of different technology stacks and because of the code Minimal and easy migration to a new tech stack
  • Different staff configurations can allow different teams to maintain different service projects, but still need to be reliable in interface calls.
  • Additional complexity, because this distribution leads to more prominent network, load, concurrency, and transaction problems, which increases the difficulty of testing, overall deployment, and operation and maintenance.

vocabulary learning

  • Registration service, a unified configuration center. After the microservice starts, it will be registered as an available service here, and the program that needs to call the service will also search for and schedule available services here.
  • RPC, or Remote Process Call, uses TCP requests at a lower level than HTTP requests to achieve two-way instant response and faster
  • gRPC, a set of RPC-based general frameworks implemented by Google, are implemented using different technologies in different scenarios. For example, the operating system uses C++ to implement the server, the back-end programs Java and Nodejs use the SDK (bottom calls C++) calls, and the browser uses the js library (WebSocket is used internally) call.
  • Avalanche, when a service is unavailable, there are still a large number of requests, causing all related services to be dragged down
  • Peak shaving, after exceeding the set concurrency (the maximum capacity of the service), the excess request will directly return failure or be placed in the delay waiting queue
  • Current limiting, setting a limit on the number of visits per unit time for a single service request (such as using counters, token buckets, leaky buckets, and client verification codes to prevent brushing), generally used in conjunction with peak shaving
  • Fuse, for the same request exceeding a certain failure rate, directly return failure for a period of time
  • Downgrade, for overload/slow response speed, put non-essential service requests in the delay waiting queue, and the status of the request itself becomes processing, so that key service requests can have better traffic and response speed

Spring Cloud Core Components

  • Eureka/Nacos, service registration and discovery, save the ip address, port number, version number, communication protocol, etc. of the microservice, use a double-layer map to correspond to the service name, instance name and actual content, and maintain heartbeat packets and eliminate useless services, if it is a cluster You need to keep the instance the same.
  • Ribbon, request load balancing, go to Eureka to find a suitable service instance and initiate a request according to the written service interface request
  • Feign/OpenFeign/Dubbo maps code calls to service interface requests. It does not need to manually write a bunch of requests as required, but calls microservices remotely through Ribbon load balancing like calling code in a project.
  • Hystrix/Sentinel, the thread pool implements service call isolation, and completes service current limiting, fusing, and degradation
  • Zuul/Kong/SpringCloudGateway, service gateway, filters requests and verifies permissions and performs actual request operations
  • Seata: Distributed Transactions

The difference between Spring Cloud and Dubbo

Spring Cloud is a comprehensive microservice framework. The core of Dubbo is a remote call framework. Because of its good performance, Dubbo is generally introduced and used together with Spring Cloud.

DDD Domain Driven Design (Domain Drive Development)

For example, split all modules and services according to domains. For example, logistics services focus on product specifications, volume, weight, etc., while order services focus on product specifications, prices, etc., regardless of whether the products concerned by the two are in the same table, but The service domain is separated, and each only focuses on the attributes it needs. The connection between the two needs to be separated as much as possible from the beginning of the single application, and then it is easy to improve into a microservice.

Middle platform

The concept of the middle platform is to extract various common parts as an intermediate layer. When developing any project, the middle platform can be directly called to complete business processing and data storage, and the project itself only needs to focus on the development of specialized parts.
Like microservices, the middle platform is a strategic and tactical design influenced by the DDD design specification.

Classification

  • The business center is responsible for various public services, such as the above-mentioned commodities, orders, payment, logistics, malls, social networking, games and other applications can be used
  • The data center is more inclined to record and sort out all process logs, and further make analysis reports to build additional systems, such as Ant Credit
  • Technology platform, implement risky or difficult technologies, such as finance, wallet, cash register, payment, live audio and video streaming, etc.

Module division of microservices

  • According to Controller-Service-Dao, it is directly divided into three modules that depend on each layer according to this structure. The advantage is that it is very easy to change from the original single application to this method. The disadvantage is that it does not well reflect the goals to be achieved by microservices. Coupling Sex is no different from the original.
  • Divided by functionality, such as users, orders, content, and products, but if the correlation between functional modules may be too strong, this separation is only applicable to a single high-complexity project.
  • Divided according to DDD, according to the DDD design specification, the functions are first separated in this way, and then the corresponding services are made. This method is generally adopted for mid-stage projects or multi-application projects
  • According to the development purpose, such as dividing into core, system management, front-end display, third-party API, toolkit, etc., it is convenient for users to carry out secondary development. Open source projects generally adopt this method.

Cross Language Microservices

Cross-language should be one of the advantages of microservices, that is, services in different domains can choose a suitable development language to develop and implement, but at the same time, this also requires that after there is a unified registration center/configuration center, other development languages ​​also need to be corresponding Implement some corresponding adaptations such as heartbeat, registration service, and local call to remote call to make the mutual calls between different services appear smooth.

Among them, thrift has achieved a certain degree of compatibility with most languages ​​such as java, .net, C++, nodejs, python, php, rust, etc., but only realizes remote calls, and does not realize the functions of configuration center and registration center.
thrift

Dubbo, on the other hand, supports configuration centers and registration centers, but only realizes java and nodejs, and does not support development languages ​​such as .net and C++. If you want to be compatible with other languages, you have to refer to the source code development yourself.
Asp.net implementation of heterogeneous SOA system architecture (compatible with dubbo)

Guess you like

Origin blog.csdn.net/u013102711/article/details/130709292