(8) What is the spring cloud Eureka of Java spring cloud enterprise rapid development architecture?

Time:2021-12-4


Spring cloud Eureka is a part of the spring cloud Netflix microservice suite. It is secondary encapsulated based on Netflix Eureka and is mainly responsible for realizing the service governance function in the microservice architecture.

Spring cloud Eureka is a rest based service and provides Java based client components. It is very convenient to register the service in spring cloud Eureka for unified management.

Service governance is an essential part of the microservice architecture. Alibaba’s open source Dubbo framework is aimed at service governance. Service governance must have a registry. In addition to Eureka, we can also use consul, etcd, zookeeper, etc. as the registry of services.

Readers who have used Dubbo should be aware that there are several registration centers in Dubbo, such as zookeeper and redis, but zookeeper is the most used.

As for the use of either method, the registry is nothing more than managing the information and status of all services. If we use examples in our life to illustrate, I think 12306 website is more appropriate.

First of all, 12306 website is like a registration center. Customers are like calling clients. When they need to take a train, they will log in to 12306 website to query the remaining tickets. If they have tickets, they can buy them, then get the train number and time, and finally start.

The same applies to programs. When you need to call a service, you first go to the Eureka to pull the list of services to see if the service you are calling is not in it, and then get the service address, port and other information, then call.

The advantage of the registration center is that you don’t need to know how many providers there are. You just need to pay attention to the registration center. Just like customers don’t need to care about how many trains are running, they just need to go to the 12306 website to see if there are tickets.

Why is Eureka more suitable as a registry than zookeeper? This is mainly because Eureka is built based on the AP principle, while zookeeper is built based on the CP principle.

There is a famous cap theorem in the field of distributed systems, that is, C is data consistency; A is service availability; P is the fault tolerance of service to network partition failure. These three characteristics cannot be satisfied at the same time in any distributed system, and at most two can be satisfied at the same time.

Zookeeper has a leader, and when the leader cannot be used, a new leader is elected through Paxos (Zab) algorithm. The task of this leader is to ensure that data is only written to this leader when writing data, and the leader will synchronize information to other nodes. Through this operation, the consistency of data can be guaranteed.

In short, Eureka is needed to ensure AP and zookeeper is needed to ensure CP.

Most of Dubbo is based on zookeeper as the registry. Eureka is the first choice in spring cloud.
​​(8) What is the spring cloud Eureka of Java spring cloud enterprise rapid development architecture?

Recommended enterprise distributed architecture source code