Eureka服务注册中心
一、 什么是服务注册中心
服务注册中心是服务实现服务化管理的核心组件,类似于目录服务的作用,主要用来
存储服务信息,譬如提供者 url 串、路由信息等。服务注册中心是 SOA 架构中最基础的设
施之一。
1 服务注册中心的作用
1,服务的注册
2,服务的发现
2 常见的注册中心有哪些
1,Dubbo 的注册中心 Zookeeper
2,Sringcloud 的注册中心 Eureka
3 服务注册中心解决了什么问题
1. 服务管理
2. 服务的依赖关系管理
4 什么是 Eureka 注册中心
Eureka 是 Netflix 开发的服务发现组件,本身是一个基于 REST 的服务。Spring Cloud
将它集成在其子项目 spring-cloud-netflix 中,以实现 Spring Cloud 的服务注册于发现,同时
还提供了负载均衡、故障转移等能力。
5 Eureka 注册中心三种角色
5.1Eureka Server
通过 Register、Get、Renew 等接口提供服务的注册和发现。
5.2Application Service (Service Provider)
服务提供方:把自身的服务实例注册到 Eureka Server 中
5.3Application Client (Service Consumer)
服务调用方:通过 Eureka Server 获取服务列表,消费服务。
二、Eureka入门案例
1 环境搭建
2 修改pom文件添加依赖
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.bjsxt</groupId>
<artifactId>springcloud-eureka-server</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>springcloud-eureka-server</name>
<description>Demo project for Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.13.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEn
coding>
<project.reporting.outputEncoding>UTF-8</project.reporting.
outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Dalston.SR5</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka-server</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
4 修改 application.properties 全局配置文件
spring.application.name=eureka-server
server.port=8761
#是否将自己注册到 Eureka-Server 中,默认的为 true
eureka.client.registerWithEureka=false
#是否冲 Eureka-Server 中获取服务注册信息,默认为 true
eureka.client.fetchRegistry=false
5 通过浏览器访问 Eureka-Server 服务管理平台