1、RPC 远程调用框架核心设计思想:在于注册中心,因为注册中心管理每个服务与服务之间的依赖关系(服务治理的概念)
2、什么是服务治理
在传统的PRC远程调用框架中,管理每个服务与服务依赖关系比较复杂。
如何以后服务与服务之间的依赖关系比较多的情况下,服务的的url管理起来比较复杂。在这个时候可以使用服务治理,管理服务与服务之间的依赖关系,可以本地负载均衡,实现服务的发现与注册,容错等。
3、服务注册:将服务信息注册到注册中心。
4、服务发现:从注册中心获取服务的信息。
5、注册中心的概念:存放服务地址的相关信息(可以理解为接口地址)
a、首先启动注册中心(eureka注册中心)
b、启动会员服务
c、会员服务在启动的时候,会把当前服务信息,比如服务的地址和端口,以别名的方式注册到注册中心上去(缓存到jvm内存中去,eureka默认会30s更新一次服务调用地址)
d、消费者在调用接口时,使用服务的别名也就是serviceId去注册中心获取实际的rpc远程调用地址。
e、如果消费者获取rpc远程调用地址后,在本地使用httpClient技术实现调用。
注:一个服务既可以作为消费者,也可以作为服务提供者。
一、注册中心的搭建:
1、maven依赖信息
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.1.RELEASE</version>
</parent>
<!-- 管理依赖 -->
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Finchley.M7</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<!--SpringCloud eureka-server -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
</dependency>
</dependencies>
<!-- 注意: 这里必须要添加, 否者各种依赖有问题 -->
<repositories>
<repository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/libs-milestone</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
2、application.yml 配置
启动Eureka服务
@EnableEurekaServer作用:开启eurekaServer
浏览器输入:http://localhost:8100/
二、注册服务的提供者
1、maven依赖信息:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.1.RELEASE</version>
</parent>
<!-- 管理依赖 -->
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Finchley.M7</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<!-- SpringBoot整合Web组件 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- SpringBoot整合eureka客户端 -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
</dependencies>
<!-- 注意: 这里必须要添加, 否者各种依赖有问题 -->
<repositories>
<repository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/libs-milestone</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
2、application.yml
启动会员服务
可以看到会员服务成功注册到eureka服务上
本文暂时没有评论,来添加一个吧(●'◡'●)