search
HomeJavajavaTutorialIn-depth analysis of springCloud's Eureka practice

1. First introduction to springcloud

Microservices are an architectural approach that will ultimately require a technical architecture to be implemented.

There are many ways to implement microservices, but the most popular one is Spring Cloud

What Spring is best at is integration, taking the best frameworks in the world and integrating them into your own projects middle.

The same is true for Spring Cloud. It integrates some of the most popular technologies now and implements functions such as: configuration management, service discovery, intelligent routing, load balancing, fuses, control bus, cluster status and so on. Its main components include:

  • Eureka: Registration Center

  • Zuul: Service Gateway
  • Ribbon: Load Balancing

  • Feign: Service Call

  • Hystix: fuse

Today we mainly get to know springcloud’s registration center Eureka

Here is an example in life:

Before the emergence of online ride-hailing, people could only call a taxi when going out. Some private cars want to be rented but are not qualified and are called black cars. Many people want to book a taxi, but unfortunately there are too few taxis and it is inconvenient. There are many private cars but they dare not stop them, and among the cars on the street, who knows which ones are willing to carry people. One wants and the other is willing to give, but there is a lack of introduction and management.

At this time, online ride-hailing platforms like Didi appeared. All private cars that want to carry passengers must register with Didi, and record your car model (service type) and identity information (contact information). Private cars that provide such services can be found on Didi, and they are clearly visible at a glance.

Anyone who wants to call a car at this time only needs to open the APP, enter your destination, select a car model (service type), and Didi will automatically arrange a car that meets your needs to serve you.

Back to springcloud’s Eureka, Eureka is like Didi, responsible for managing and recording service provider information. Service callers do not need to find services themselves, but tell Eureka their needs, and then Eureka will tell you the services that meet your needs. At the same time, the "heartbeat" mechanism is used to monitor the relationship between the service provider and Eureka. When a problem occurs with a service provider, Eureka will naturally remove it from the service list.

This realizes automatic registration, discovery, and status monitoring of services.

In-depth analysis of springClouds Eureka practice

Eureka: It is the service registration center (can be a cluster), exposing its own address to the outside world

Provider: Register your own information with Eureka after startup ( address, what services are provided)

Consumer: Subscribe to Eureka for a service, Eureka will send a list of all provider addresses of the corresponding service to the consumer, and regularly update

heartbeat (renewal) : Providers regularly refresh their status to Eureka through http

Practice:

Eureka registration center structure chart:

In-depth analysis of springClouds Eureka practice

##Complete the pom.xml file and add dependencies

The following is the main part of the pom file

<parent>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-starter-parent</artifactId>
   <version>2.0.3.RELEASE</version>
   <relativePath/> <!-- lookup parent from repository -->
</parent>

<properties>
   <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
   <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
   <java.version>1.8</java.version>
   <spring-cloud.version>Finchley.RELEASE</spring-cloud.version>
</properties>

<dependencies>
   <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-web</artifactId>
   </dependency>
   <dependency>
      <groupId>org.springframework.cloud</groupId>
      <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
   </dependency>

   <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-test</artifactId>
      <scope>test</scope>
   </dependency>
</dependencies>

<dependencyManagement>
   <dependencies>
      <dependency>
         <groupId>org.springframework.cloud</groupId>
         <artifactId>spring-cloud-dependencies</artifactId>
         <version>${spring-cloud.version}</version>
         <type>pom</type>
         <scope>import</scope>
      </dependency>
   </dependencies>
</dependencyManagement>

<build>
   <plugins>
      <plugin>
         <groupId>org.springframework.boot</groupId>
         <artifactId>spring-boot-maven-plugin</artifactId>
      </plugin>
   </plugins>
</build>

Edit startup class

@SpringBootApplication
@EnableEurekaServer // 声明这个应用是一个EurekaServer
public class SpringcloudEurekaServerApplication {

   public static void main(String[] args) {

      SpringApplication.run(SpringcloudEurekaServerApplication.class, args);
   }
}

Write application.yml configuration

server:
  port: 8081 # 端口
spring:
  application:
    name: eureka-server # 应用名称,会在Eureka中显示
eureka:
  client:
    register-with-eureka: false # 是否注册自己的信息到EurekaServer,默认是true
    fetch-registry: false # 是否拉取其它服务的信息,默认是true
    service-url: # EurekaServer的地址,现在是自己的地址,如果是集群,需要加上其它Server的地址。
      defaultZone: http://127.0.0.1:${server.port}/eureka

Run the project: visit http://127.0.0.1:8081

In-depth analysis of springClouds Eureka practice

At this time, an Eureka registration center is successfully built.

The above is the detailed content of In-depth analysis of springCloud's Eureka practice. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
面试反馈 Spring Cloud 的25连环炮面试反馈 Spring Cloud 的25连环炮Aug 24, 2023 pm 03:57 PM

Spring Cloud目前相当的火热,也差不多是java开发者必备技能之一了。面试的时候被问,那也是正常不过了,很多人可能用来很久,但是没有去了解过原理,面试照样挂掉。

比较与选择指南:SpringCloud和SpringBoot的功能对比比较与选择指南:SpringCloud和SpringBoot的功能对比Dec 29, 2023 pm 06:36 PM

SpringCloud和SpringBoot是目前Java领域中最热门的开源框架,它们分别提供了一套完善的微服务架构和快速构建应用程序的解决方案。本文将对它们的功能进行比较,并给出选择指南,以帮助读者了解它们的优势和适用场景。SpringBoot是一个用于开发Java应用程序的框架,它提供了一个简化的开发流程,集成了大量常用的功能和组件,减少了开发者的工作量

springcloud五大核心组件是哪些springcloud五大核心组件是哪些Jun 12, 2023 pm 03:51 PM

springcloud五大核心组件是:1、Eureka,实现服务治理;2、Ribbon,提供客户侧的软件负载均衡算法;3、Hystrix断路器,防止一个应用程序多次试图执行一个操作;4、Zuul,具有api网关,路由,负载均衡等多种作用;5、Config,进行配置管理。

SpringCloud和SpringBoot在微服务领域的应用方式的对比和分析SpringCloud和SpringBoot在微服务领域的应用方式的对比和分析Dec 29, 2023 pm 03:45 PM

近年来,随着云计算和分布式架构的兴起,微服务架构的应用越来越广泛。而SpringCloud和SpringBoot作为Java开发中的两个重要框架,对于微服务的实现起到了重要的作用。然而,很多人对于它们在微服务领域的不同应用方式还存在一定的疑惑。本文将从不同的角度探索SpringCloud和SpringBoot在微服务中的应用方式。首先,我们来了解一下Spri

Idea springboot springCloud热加载热调试的常用方法有哪些Idea springboot springCloud热加载热调试的常用方法有哪些May 18, 2023 pm 05:43 PM

场景描述在项目开发的过程中,需要修改调试的时候偶每次都需要重启项目浪费时间,下面是我整理的两种常用的两种方式方式一修改启动配置方式(主要针对debug模式下)点击启动配置=》editconfigrations&hellip;configration下面修改Updateclassesandresourceson&lsquo;update&lsquo;action:当用户主动执行更新的时候更新快捷键:Ctrl+F9onframedeactication:在编辑窗口失去焦点的时

SpringCloud-Spring Boot Starter使用测试实例分析SpringCloud-Spring Boot Starter使用测试实例分析May 16, 2023 am 11:10 AM

SpringBootStarter是什么?SpringBootStarter是在SpringBoot组件中被提出来的一种概念、简化了很多烦琐的配置、通过引入各种SpringBootStarter包可以快速搭建出一个项目的脚手架。比如我们经常用的一些:spring-boot-starter-web:spring-boot-starter-data-redis:spring-boot-starter-data-mongodb:spring-boot-starter-data-jpa:spring-b

springcloud和springboot有什么区别springcloud和springboot有什么区别Dec 28, 2023 pm 03:34 PM

springcloud和springboot的区别:1、作用;2、使用方式;3、创作初衷;4、目的;5、集成性;6、扩展性;7、复杂性;8、社区支持;9、安全性;10、部署和运维。详细介绍:1、作用,Spring Boot主要的作用是为微服务开发提供一种快速的方式,简化配置文件,提高工作效率,而Spring Cloud则是一个综合管理框架,用于给微服务提供一个综合管理框架等等。

从架构角度看SpringCloud与SpringBoot的差异从架构角度看SpringCloud与SpringBoot的差异Dec 29, 2023 pm 04:13 PM

从架构角度看SpringCloud与SpringBoot的差异引言:在当今的互联网时代,构建分布式系统已经成为了一种必要的需求。而SpringBoot和SpringCloud正是为了满足这个需求而诞生的。尽管它们都是由Spring框架所提供的解决方案,但从架构角度来看,它们存在着一些重要的差异。本文将从架构的角度出发,对SpringBoot和SpringCl

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Tools

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft