Moment For Technology

SpringCloud, which can be understood by laymen, missed the blood loss!

Posted on Dec. 2, 2022, 3:01 a.m. by Brooke Clark
Category: The back-end Tag: java spring Load balancing Java EE

One, foreword

You have to be bald to be strong

Those who know me may know that I went to an internship these days. The company said that I used SpringCloud(but I don't think it was used very hard).

Therefore, this article will mainly talk about some basic knowledge of SpringCloud. (I just learned to sell, mainly as I learn SpringCloud notes!) Of course, my level is limited, there may be some wrong concepts/knowledge points, please feel free to comment in the area to correct ah ~~

SpringCloud GitHub Demo:

  • Github.com/ZhongFuChen...

Project structure diagram:

What is cluster/Distributed/microservices /SOA?

For a tech geek like me, when I see these words (cluster/distributed/microservices /SOA), it just feels out of reach (tall technology!!) . Just like when learning Java object-oriented, in the forum to read the information, inadvertently see "aspect oriented programming", also think that this is far away (tall still technology!!) .

But when it comes to "aspect oriented programming", it's not that big of a deal. It's just that the name fooled me...

I wonder if you were intimidated by the names cluster/distributed/microservice /SOA when you first came across them?

  • Let me tell you briefly what these nouns mean

2.1 What is a Cluster

The following is from Wikipedia:

Computer cluster or cluster is a computer system that uses a set of loosely integrated computer software and/or hardware that are linked together in a highly close collaboration to perform computing work. In a sense, they can be seen as a computer. The individual computers in a clustered system are usually called nodes and are usually connected over a LAN, but there are other possible connections. Cluster computers are often used to improve the computing speed and/or reliability of a single computer. Cluster computers are typically much more expensive than individual computers, such as workstations or supercomputers

Cluster technical features:

  • By multiple computers to complete the same work, to achieve higher efficiency.
  • The contents and working process of two or more machines are exactly the same. If one crashes, the other one can come into play.

It's pretty clear on Wikipedia, so let me give you an example.

  • Xiao Zhou writes Java programs in the company, but the company's business is growing, a Java developer mayHands are fullXiao Zhou sometimes has toA false, please. So he invited 3y overDo Java development together. Weekly and 3y write Java programs, but 3y mightsomethingI have to go back to school. No matter, the company still has Xiao Zhou to do Java development, the company development can continue to operate.
    • 3y and Xiao Zhou both work on Java development.
    • 3Y is here. Xiao Zhou can share some of his work.
    • 3Y is on leave, and Xiao Zhou is here.

I wrote a 910 convenience net to publish go to the server, more and more people visited now, visit a bit slow, how to do?? Very simple, (only charge money to become stronger), add configuration (add CPU, add memory). After upgrading the configuration, more and more visitors, so found that can not help but use, in this machine to add configuration has not solved, how to do?? Very simple, (only charge money to be able to become strong), I buy a server again, 910 convenience net also publish to buy this server to go up newly.

Features:

  • These two servers are running the same system -910 Convenience network

Benefits:

  • Instead of just one machine handling access, there are now two machines handling access, sharing the stress.
  • If you forget to pay for one of them, it won't work for a while. It doesn't matter. There's another one available.

Cluster: Same business, deployed on multiple servers (different servers running the same code, doing the same thing)

2.2 What is distributed

The following is from Wikipedia:

A distributed system is a group of computers that are connected through a network to transmit messages and communicate with each other and coordinate their behavior. Components interact with each other to achieve a common goal.

Let me give you an example:

  • Now the company has Xiao Zhou and 3Y do Java development together, do Java development in general, jQuery, AJAX can write a little, so we do all the work. However, 3Y is not very familiar with the front end, sometimes debugging half a day can not be adjusted. The boss thinks 3Y is real! So let Xiao ZhouSpecifically to handle the front endThing to do. So 3y is happy. OkWrite your own Java, the front endspecialXiao Zhou is in charge. So, xiao Zhou and 3y becomeCollaborative development.
    • 3Y is not familiar with the front end (can write it out), but it can take a lot of time to debug
    • With a few weeks devoted to the front end, 3y could focus on writing his own Java program.
    • It's all about getting the project running and iterating.

My 910 convenience network has been deployed to two servers, but more and more people are visiting. And now it's starting to get too much. So what now? That continue to make money stronger?? As a rational person, I have to figure out what's wrong. Now there are several modules of the 910 convenience network, all in the same Tomcat.

In fact, some modules access is very low (such as background management), then I can do this: each module extracted out of a large number of visits to the module with a good server installed, no one to access the module with poor server installed. The advantages of this are as follows: first, resources are properly utilized (modules that no one accesses use poor performance servers, while modules with large traffic volume can improve performance separately). Two, the coupling degree is reduced: each module is independent, each do their own thing (professional people do professional things), easy to expand

Features:

  • The functions of the 910 convenience network will be split, modules are independent, when using these independent modules together is a system.

Benefits:

  • Modules are independent, each do their own things, easy to expand, high reuse
  • High throughput. A task that takes one machine to run for 10 hours may be completed in 2 hours by using a distributed run of 10 machines (breaking the task into 10 smaller tasks)

Distributed: a business is divided into multiple sub-businesses, deployed on different servers (different servers, running different code, for the same purpose)

2.3 Cluster/Distributed

Cluster and distributed do not conflict, you can have distributed cluster

Now 3Y is a bigger company, with 5 guys doing Java, 4 guys doing front end, 2 guys doing testing, and 1 guy doing DBA.

  • Java, front-end, test, and DBA relationships are considered distributed
  • 5 Java as cluster (front end, same with test)...

2.4 Distributed/microservices /SOA

In fact, I think the three concepts of distributed/microservices /SOA are pretty much the same, just understand one of them and then apply your understanding to the top. There's no need to break down the specifics of each concept (of course, I'm looking forward to having someone comment in the comments section).

References:

  • What is the difference between distributed and clustered? www.zhihu.com/question/20...
  • Distributed, cluster, the difference between micro service, SOA blog.csdn.net/heatdeath/a...

3. CAP theory

From the above mentioned concept of distributed, we have known that a simple understanding of distributed is: a business is divided into multiple sub-businesses, deployed on different servers

  • In general, a child business we call a node.

If you're familiar with some of the basic concepts of distribution, you'll have heard of CAP. For example, if you have learned MySQL's InnoDB storage engine, you must have heard of ACID!

First, let's take a look at what CAP stands for:

  • C: Consistency
    • All nodes have the latest version of the data
  • A: Availability
    • Data is highly available
  • P: Partition-tolerance
    • Partitions are tolerated on the network. The network between partitions is unreachable.

If you have three nodes (they are clustered), all three nodes can communicate with each other:

Since our system is distributed, communication between nodes is carried out through the network. As long as it is distributed, it is very likely that the whole network will be divided into several areas because of some failure and some nodes will not be connected to each other.

  • Data is spread over these disconnected regions, called partitions

Now that the network partition is in place, a request comes in to register an account.

At this point, we cannot communicate with node 1 and node 3, so we have a choice:

  • ifallowIf the current user registers an account, the registered data is stored only on node 1 and node 2 or on node 2 and node 3synchronous, because the records of node 1 and node 3 cannot be synchronized.
    • This is a case of choosing availability over consistency.
  • ifDon't allowThe current user registers an account (i.eWait until theNode 1 and node 3 resume communication). Once communication is restored between nodes one and three, we canEnsure that the node has the latest version of the data.
    • In this case, you're essentially choosing consistency over availability.

3.1 Summarize CAP theory again

In general, when we talk about distributed systems, P: Partition-tolerance, this is required, this is an objective existence.

CAP can't be taken into account completely. As can be seen from the above example, we can choose either AP or CP. However, it is important to note that the choice of AP does not mean that C is completely abandoned. It doesn't mean that after choosing CP, A completely abandons it!

In CAP theory, the consistency represented by C is strong consistency (the data of each node is the latest version). In fact, there are other levels of consistency:

  • Weak consistency: Weak consistency is relative to strong consistency, it is not guaranteed to always get the latest value;
  • Eventual consistency: The time requirement is relaxed. At a certain point after the operation response is completed, the data of multiple nodes that are called will finally reach the agreement

The range of availability can be defined as a continuous range from 0 to 100%.

Therefore, CAP theory defines that "strong consistency" and "extreme availability" cannot be achieved at the same time under the condition that network partitions are tolerated.

References:

  • What exactly does "P" mean in CAP theory? www.zhihu.com/question/54...
  • On the Basic issues of distributed systems: Availability and consistency: m.aliyun.com/yunqi/artic...
  • Distributed system theory of the CAP: www.hollischuang.com/archives/66...
  • Why can CAP theory have perfect CA without P? www.zhihu.com/question/28...
  • Don't know a little CAP theory, you say you do distributed? www.yunweipai.com/archives/84...

Read more:

  • On distributed transactions: m.aliyun.com/yunqi/artic...

SpringCloud is that simple

I believe that by this point, you have a certain understanding of distributed/microservices, in fact, from the concept alone, it is very easy to understand. I'm just probably fooled by the name.

Now I will talk about the most basic knowledge of SpringCloud

4.1 why do I need SpringCloud?

As mentioned earlier, from the perspective of distributed/microservices: breaking our large project into smaller modules. These small modules work together to accomplish the function.

Here's an example that might not be appropriate (the reality might not be this split, but the meaning would be fine) :

SpringCloud provides a complete solution to all kinds of problems that arise when modules are split out!

  • Note: These modules are separate subsystems (different hosts).

Basic features of SpringCloud:

  • Service governance: Spring Cloud Eureka
  • Client load balancing: Spring Cloud Ribbon
  • Service fault-tolerant protection: Spring Cloud Hystrix
  • Declarative service invocation: Spring Cloud Feign
  • API gateway service: Spring Cloud Zuul
  • Distributed configuration center: Spring Cloud Config

Advanced features of SpringCloud (not covered in this article) :

  • Message Bus: Spring Cloud Bus
  • Message-driven microservices: Spring Cloud Stream
  • Distributed service tracking: Spring Cloud Sleuth

Eureka

What could go wrong? The first problem is communication between subsystems. The subsystems are not in the same environment as each other, which requires remote calls. Remote calls might be implemented using httpClient, WebService, and so on.

Since this is a remote call and you have to know the IP address, we might have the following scenario.

  • Function implementation 1: Service A needs to call service B
    • Call service B in service A's code,Explicitly invoked by IP address:http://123.123.123.123:8888/java3y/3
  • Function realization two: service A invokes service B, service B invokes service C, and service C invokes service D
    • Call service B in service A's code, explicitly using the IP address:http://123.123.123.123:8888/java3y/3B-C, C-D
  • Function realization iii: Service D invokes service B, and service B invokes service C
    • Call service B in service D code, explicitly using the IP address:http://123.123.123.123:8888/java3y/3B-C
  • . Etc., etc.

If the IP address of our SERVICE B changes, think about what will happen: Service A, service D (etc.) need to manually update the address of service B

  • In the case of many services, maintaining these static configurations manually is a nightmare!

To address the maintenance of service instances (IP addresses) in microservice architectures, a number of service governance frameworks and products have been created. These frameworks and products are implemented around service registration and service discovery mechanisms to complete the automatic management of microservice application instances.

Eureka is commonly used as our service governance framework in SpringCloud.

Our question:

  • There are now four services, A, B, C, and D, which call each other (and their IP addresses are likely to change). Once the IP address of A service changes, the code in the service has to change, and it is very difficult to manually maintain the static configuration (IP)!

Here's how Eureka works:

  • Create an E service, register the information of four services A, B, C and D to the E service, and the E service maintains the registered information

Services A, B, C and D can get the Eureka(Service E) registration list. Services A, B, C, and D call each other by service name instead of by specific IP address!

  • Get the registration list -- the registration list has the service name -- can get the service specific location (IP).
  • The IP address of the service will change, but the service name will not change.

5.1 details had been

Eureka is dedicated to registering other services called Eureka Server(service registry), and the remaining services registered to Eureka Server are called Eureka clients.

The Eureka Server is configured as follows:


    register-with-eureka: false     #false means not to register yourself with the registry.
    fetch-registry: false     #false indicates that my side is the registry and my responsibility is to maintain the service instance, not to retrieve the service
Copy the code

Eureka Client is divided into service provider and service consumer.

  • But it is possible that a service is both a service provider and a service consumer.

Don't be too surprised to see on the web that one of SpringCloud's service configurations is not "registered" with Eureka Server (but it is possible to get a list of Eureka services).

  • It is likely that the author sees the service as a pure service consumer, and that a pure service consumer does not need to provide the service externally and therefore does not need to register with Eureka

eureka:
  client:
    register-with-eureka: false  # Currently microservices are not registered with Eureka (consumer side)
    service-url: 
      defaultZone: http://eureka7001.com:7001/eureka/,http://eureka7002.com:7002/eureka/,http://eureka7003.com:7003/eureka/  

Copy the code

The following is the governance mechanism of Eureka:

  • Service provider
    • Service registration: The service registers itself with the Eureka Server by sending REST requests when it is started, along with some metadata information about its own service.
    • ** Service renewal: ** After registering the service, the service provider maintains a heartbeat that continuously tells the Eureka Server that "I'm alive",
    • Service offline: When a service instance performs a normal shutdown operation, it triggers a SERVICE offline REST request to the Eureka Server, telling the service registry: "I'm going offline."
  • Service consumer
    • Get services: When we start the service consumer, it sends a REST request to the service registry to get the list of services registered above
    • Service invocation: After obtaining the service list, the service consumer can obtain the instance name of the specific service and the metadata information of the instance through the service name. Service providers in the same Zone are preferentially accessed when making service calls.
  • Eureka Server(Service Registry)
    • ** Invalid cull: ** The current list of services that have timed out (default: 60 seconds) and have not been renewed will be culled every time (default: 90 seconds).
    • Self protection:. During the operation of EurekaServer, the EurekaServer calculates whether the heartbeat failure rate is lower than 85% within 15 minutes (usually due to network instability). The Eureka Server protects the current instance registration information so that the instance does not expire and the registration information is protected as much as possible.

In the end, we have this picture:

Here's an example:

  • 3Y went shopping with his girlfriend in Oriental Baotai, but I don't know what fun there is in Oriental Baotai. So I went to the property management office to search the list of Oriental Botai merchants and found uniqlo on the first floor, Starbucks on the second floor and McDonald's on the third floor.
  • Next to the Uniqlo is the newly opened KFC, with a big sign on the wall saying "Welcome KFC to Botai Orient".
  • Businesses need to pay regular property management fees.
  • Property to maintain the stability of Oriental Baotai. If a business does not want to operate at Botai Orient, let the property know. The property will naturally remove its merchant list in Oriental Baotai.

Excellent Blog:

  • Spring Cloud had a: blog.csdn.net/sunhuiliang...
  • The Spring Cloud Netflix - service registration and service discovery - the use of Eureka: zhuanlan.zhihu.com/p/26472547
  • Micro service architecture: Eureka parameters configuration items a: www.cnblogs.com/fangfuhai/p...

Introduce RestTemplate and Ribbon

With the Eureka service Governance framework, we can obtain the location (IP) of a specific service instance by its name. Generally, when using SpringCloud, you do not need to manually create HttpClient to make remote calls.

You can use the Spring-wrapped RestTemplate utility class, which is simple to use:


	// The traditional way to directly write dead IP is not good!
    //private static final String REST_URL_PREFIX = "http://localhost:8001";
	
	// Service instance name
    private static final String REST_URL_PREFIX = "http://MICROSERVICECLOUD-DEPT";

    /** * Use restTemplate to access restful interfaces. The (URL, requestMap, * responseBean.class) parameters represent the REST request address, the request parameters, and the object type to which the HTTP response conversion is converted. * /
    @Autowired
    private RestTemplate restTemplate;

    @RequestMapping(value = "/consumer/dept/add")
    public boolean add(Dept dept) {
        return restTemplate.postForObject(REST_URL_PREFIX + "/dept/add", dept, Boolean.class);
    }

Copy the code

To achieve high availability of services, we can cluster service providers. For example, now a seckill system has been designed and is ready to go live. On November 11, in order to support high concurrency, we switched on multiple machines to support concurrency.

Now, if you want these three seckill systems to split user requests properly (technically, load balancing), you might think of Nginx.

SpringCloud also supports load balancing, but it's client-side load balancing, implemented by the Ribbon!

There are two types of load balancing:

  • Client Load Balancing (Ribbon)
    • The list of service instances is allocated on the client using a load balancing algorithm.
    • (We already know from the above: clients can get a list of services from Eureka Server and use a load-balancing algorithm to select one of the multiple servers to access when sending a request)
  • Server Load Balancing (Nginx)
    • The list of service instances is on the server, and the server allocates the load balancing algorithm

So, our picture can be drawn like this:

6.1 Ribbon details

The Ribbon supports load balancing. The default load balancing policy is polling. You can customize your own load balancing policy.


@Configuration
public class MySelfRule
{
	@Bean
	public IRule myRule(a)
	{
		//return new RandomRule(); // The Ribbon defaults to polling. I have customized it to be random
		//return new RoundRobinRule(); // The Ribbon defaults to polling. I have customized it to be random
		
		return new RandomRule_ZY();// I customize it to 5 times per machine}}Copy the code

The implementation is simple: just inherit AbstractLoadBalancerRule class and override the public Server Choose (ILoadBalancer LB, Object key).

SpringCloud uses AP in CAP theory. The retry mechanism can also be configured in the Ribbon (you can search for it)

Here's an example:

  • After a few months with his girlfriend, he went to Oriental Baotai again. Due to a bad memory, I went to the property management to get a list of Oriental Baotai merchants.
  • This time I saw Oriental Baotai opened a McDonald's, one on the second floor, one on the third floor. The original business was so good that in order to improve user experience, an extra McDonald's was opened on the second floor.
  • 3y asks his girlfriend, "Which McDonald's is the best place to go? Shall we flip a coin?" 3y's girlfriend said, "Are you stupid? You must go to the nearest one."

Excellent Blog:

  • The principle of lu an lu Spring Cloud Ribbon - load balancing strategy: www.cnblogs.com/kongxiangha...

7. Hystrix

So far, our service looks pretty good: we can invoke other services remotely based on the service name, enabling load balancing on the client side.

But what if one service suffers a delay when we invoke multiple remote services?

In the case of high concurrency, due to the delay of a single service, all requests may be delayed, and even in a few seconds the service will be overloaded, the resources will be exhausted, and finally the distributed system will not be available, which is called "avalanche".

To address these issues, Spring Cloud Hystrix implements a series of service protection features such as circuit breakers and thread isolation.

  • Fallback: When a service unit fails (similar to an electrical short circuit), it returns an error response to the caller through the fault monitoring of the circuit breaker (similar to a fuse blowing), rather than waiting for a long time. In this way, the thread will not be occupied for a long time due to the invocation of the fault service, which avoids the spread of the fault in the distributed system.
  • Resource/dependency isolation (thread pool isolation) : This creates a separate thread pool for each dependent service, so that a high latency situation for one dependent service affects only that dependent service invocation and does not slow down other dependent services.

Hystrix provides several fuse key parameters: sliding window size (20), fuse switch interval (5s), error rate (50%)

  • Every time 50% of 20 requests fail, the fuse will be opened, and the service will be called again at this time, and will directly return failure, no remote service will be called.
  • After 5 seconds, retest the trigger condition to determine whether to close the fuse or continue to open it.

Hystrix also has powerful functions such as request merge and request cache, which I will not specify here, but you can continue to learn more about it

7.1 Hystrix dashboard

Hystrix Dashboard: Monitors Hystrix metrics in real time. Real-time feedback from the Hystrix Dashboard helps us quickly identify problems in the system and take immediate action.

Startup page:

Monitor single service page:

Here's what we're doing now:

In addition to a monitoring page that can be opened for a single instance, there is a monitoring endpoint /turbine. Stream that is used for the cluster. From the naming of the endpoints, Turbine can be introduced to aggregate monitoring information and provide the aggregated information to the HystrixDashboard for centralized display and monitoring.

Here's an example:

  • 3Y and girlfriend decided to go to Wanda play, go to wanda's parking lot found in the negative one layer has been greatly written "negative one layer is full, please negative two, negative two empty parking space and 100!"
  • At this time, 3Y said to his girlfriend: "Wanda parking lot is doing a good job, if it did not directly inform me that the first floor is full, maybe I go to the first floor to find a place, if a bunch of people run to the first floor but can not find a parking space, I am afraid it will be jammed." 3Y continued: "It's also good to see the status of the parking space. There's a sensor on the top of the parking space. If it's red, it's stopped, and if it's green, it's empty."
  • 3y girlfriend disdained to say: "Your words are really much"

References:

  • Hystrix: Why is it an essential open source framework for every system? zhuanlan.zhihu.com/p/34304136
  • Translate documents of understanding Hystrix: zhuanlan.zhihu.com/p/28523060
  • Talk about my understanding of service fusing, relegation: blog.csdn.net/guwei911198...
  • Hystrix "green mountain" : a few article segmentfault.com/u/yedge/art...

Eight, introduce Feign

The Ribbon and Hystrix are widely used as basic toolclass frameworks for microservices. We will find that the use of both frameworks appears almost at the same time.

To simplify our development, Spring Cloud Feign came along! Based on Netflix Feign, it integrates Spring Cloud Ribbon with Spring Cloud Hystrix. In addition to the power of integrating the two, it also provides declarative service invocation (no longer via RestTemplate).

Feign is a declarative, template-based HTTP client. Using Feign in the Spring Cloud, we can make a request for a remote service using HTTP the same coding experience as a call to a local method. The developer is completely unaware that it is a remote method, much less that it is an HTTP request.

Here's a quick look at how Feign elegantly implements remote calls:

Service binding:


// value -- Specifies which service to call
// fallbackFactory--  fallbackFactory
@FeignClient(value = "MICROSERVICECLOUD-DEPT", fallbackFactory = DeptClientServiceFallbackFactory.class)
public interface DeptClientService {


    // With Feign, we can use SpringMVC annotations to bind services!
    @RequestMapping(value = "/dept/get/{id}", method = RequestMethod.GET)
    public Dept get(@PathVariable("id") long id);

    @RequestMapping(value = "/dept/list", method = RequestMethod.GET)
    public ListDept list(a);

    @RequestMapping(value = "/dept/add", method = RequestMethod.POST)
    public boolean add(Dept dept);
}
Copy the code

Fuses used in Feign:


/** * use circuit breakers in Feign ** This is mainly for handling the exception error (service is not available during downdowngrade/fuse, fallback will find here) */
@Component // Don't forget to add, don't forget to add
public class DeptClientServiceFallbackFactory implements FallbackFactoryDeptClientService {
    @Override
    public DeptClientService create(Throwable throwable) {
        return new DeptClientService() {
            @Override
            public Dept get(long id) {
                return new Dept().setDeptno(id).setDname("The ID:" + id + "No, there is no corresponding information, degraded information provided by the Consumer client, the service Provider is closed at this time.")
                        .setDb_source("no this database in MySQL");
            }

            @Override
            public ListDept list(a) {
                return null;
            }

            @Override
            public boolean add(Dept dept) {
                return false; }}; }}Copy the code

Call:

Nine, out of Zuul

Based on the above learning, our current architecture is likely to look like this:

There are two problems with such an architecture:

  1. Routing rules and maintenance of service instances: The outer load balancer (Nginx) needs to maintain a list of all service instances (OpenService in the figure)
  2. Signature validation, login check redundancy problem: in order to guarantee the safety of the foreign service, we in a service interface, implementation of a service often has certain permissions checking mechanism, but our service is independent, we have to in these applications are implementing such a set of validation logic, this will cause validation logic of redundancy.

Let's draw a picture to understand:

Each service has its own IP address, and Nginx must maintain the address of each service instance in order to properly forward requests to the service!

  • To make matters worse, the IP addresses of these service instances may change, and the divisions between the services may also change.

http://123.123.123.123

http://123.123.123.124

http://123.123.123.125

http://123.123.123.126

http://123.123.123.127

Copy the code

Shopping cart and order module can only be accessed normally after the user has logged in. Based on the current architecture, only the checkout logic can be written in both shopping cart and order module, which is undoubtedly redundant code.

To solve these common architectural problems, the concept of API gateways was born. SpringCloud Zuul provides an API gateway component based on the Netfl IX Zuul implementation in SpringCloud.

Spring Cloud Zuul solves these two problems:

  • By integrating with SpringCloud Eureka, SpringCloud Zuul registers itself as an application under Eureka service governance, while obtaining instance information for all other microservices from Eureka. The outer invocation must pass through the API gateway, leaving the maintenance of the service instance to the service governance framework automatically.
  • In order to intercept and verify the microservice interface, uniform invocation is made on THE API gateway service to pre-filter the microservice interface.

Zuul is inherently self-protected with thread isolation and circuit breakers, as well as client-side load balancing for service calls. That said: Zuul also supports Hystrix and Ribbon.

There's a lot more to know about Zuul (which I won't go into here for space reasons) :

  • Route matching (Dynamic Routing)
  • Filter implementation (dynamic filter)
  • By default, cookies and sensitive HTTP headers are filtered out (additional configuration)

9.1 Possible Questions about Zuul

Zuul supports the Ribbon and Hystrix, which also provides load balancing for clients. Isn't our Feign also doing client-side load balancing and Hystrix? Now that Zuul has been implemented, is our Feign still necessary?

Or you can think of it this way:

  • Zuul is the only exposed interface which is equivalent to routing the controller's request, while Ribbonhe and Fegin route the service's request
  • Zuul does the load balancing of the outermost requests, while the Ribbon and Fegin do the load balancing of service calls across microservices within the system

With Zuul, do you still need Nginx? Can they use it together?

  • Zuul and Nginx can be used together (after all, we can cluster Zuul to achieve high availability). It depends on the complexity of the architecture (business)

References:

  • Microservices and API Gateways (part 1) : Why do WE need AN API Gateway? : blog.didispace.com/hzf-ms-apig...
  • Talk about the API gateway: www.jianshu.com/p/b52a2773e...
  • Talk about API Gateway in micro service Gateway (API) : www.cnblogs.com/savorboard/...
  • API Gateway performance comparison: NGINX vs. ZUUL vs. Spring Cloud Gateway: www.360doc.com/content/18/...
  • About API gateway background, architecture, as well as the floor plan: www.infoq.com/cn/news/201...
  • Zuul and nginx:zhuanlan.zhihu.com/p/37385481

SpringCloud Config

With the expansion of the business, our services will be more and more, more and more. Each service has its own configuration file.

Since it's a configuration file, the thing that gives us the configuration, it's going to change a little bit.

For example, in our Demo, each service has the same configuration file. If we ever need to change the password in the configuration file, we'll have to change all three.

In a distributed system, a change in the basic service information is likely to cause a series of updates and restarts

The Spring Cloud Config project is a configuration management solution for distributed systems. It consists of the Client and the Server. The Server stores the configuration file and provides the content of the configuration file in the form of an interface. The Client obtains the data through the interface and initializes its own applications based on the data.

  • To put it simply, using Spring Cloud Config is to place configuration files in a unified location (such as GitHub) and get them from the client through the interface.
  • When you change a profile on GitHub, the app loads the modified profile.

SpringCloud Config:

  • On the SpringCloud Config server, the default implementation of the configuration repository is Git, and we can also configure SVN.
  • Encryption and decryption of information in the configuration file
  • The configuration file has been modified. I hope to dynamically refresh the configuration without restarting, and use ~ with Spring Cloud Bus

Possible questions about using SpringCloud Config: The difference between application.yml and bootstrap.yml

  • www.cnblogs.com/BlogNetSpac...

conclusion

This article mainly wrote the basic knowledge of SpringCloud, I hope you can help after reading ~

There are also a lot of information about SpringCloud. I have sorted out some information which I think is better. If you want to go deeper, please check the resources below

SpringCloud Article Series References:

  • Chapter in the history of the most simple SpringCloud tutorial | end blog.csdn.net/forezp/arti...
  • Spring Cloud based tutorial the programmer DD blog.didispace.com/Spring-Clou...
  • Spring Cloud series "Pure Smile" : www.ityouknow.com/spring-clou...
  • SpringCloud series: www.cnblogs.com/woshimrf/ta...
  • SpringCloud series "crazy little white" : www.cnblogs.com/huangjuncon...
  • SpringCloud official document: the projects. Spring. IO/spring - clou...
  • Spring Cloud.cc /spring-clou...

Reference books:

  • SpringCloud Microservices In Action

SpringCloud GitHub Demo: SpringCloud GitHub Demo:

  • Github.com/ZhongFuChen...

Open source project covering all knowledge points of Java backend (5.8K STAR) :Github.com/ZhongFuChen...

If you want to follow my updated articles and share the dry goods, wechat search Java3y.

The contents of the PDF document are hand hit, any do not understand can directly ask me (the public number has my contact information).

Search
About
mo4tech.com (Moment For Technology) is a global community with thousands techies from across the global hang out!Passionate technologists, be it gadget freaks, tech enthusiasts, coders, technopreneurs, or CIOs, you would find them all here.