一、什么是服务注册中心
服务注册中心是服务实现服务化管理的核心组件,主要用来存储服务信息,譬如提供者url串、路由信息等。服务注册中心是SOA架构中最基础的设施之一
1、服务注册中心的作用
(1)服务的注册
(2)服务的发现
2、常见的注册中心有哪些
(1)dubbo的注册中心zookeeper
(2)SpringCloud的注册中心Eureka
3、服务注册中心解决了什么问题
(1)、服务管理
(2)、服务依赖关系的管理
4、什么是Eureka 注册中心
Eureka是Netflix开发的服务发现组件,本身是一个基于REST服务,Spring Cloud将它集成在其子项目spring-cloud-netflix,以实现Spring Cloud 的服务注册与发现,同时还提供了负载均衡,故障转移等能力
5、Eureka 注册中心的三种角色
5.1 Eureka Server
通过 Register、Get、Renew 等接口提供服务的注册和发现
5.2 Application Service(Service Provider)
服务提供方,把自身的服务实例注册到Eureka Server 中
5.3 Application Client (Service Consumer)
服务调用者
通过从Eureka Server 获取服务列表,消费服务
二、Eureka 入门案例
1、创建项目
2、修改pom.xml文件,添加依赖
<!-- 指定jdk --> <properties> <java.version>1.8</java.version> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> </properties> <dependencyManagement> <dependencies> <!-- https://mvnrepository.com/artifact/org.springframework.cloud/spring-cloud-dependencies --> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-dependencies</artifactId> <version>Greenwich.RELEASE</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> </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> <version>1.4.7.RELEASE</version> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> |
3、创建程序启动类
/** } |
4、修改application.properties 全局配置文件
spring.application.name=eureka-server # 是否将自己注册到Eureka-Server 服务中,默认是ture # 是否从 Eurek-Server 中获取服务列表 默认为true |