java手把手教你搭建简单的后台服务器(二)
2017-09-19 本文已影响441人
代码界的扫地僧
后台服务器搭建不懂得先看一下java手把手搭建简单的后台服务器(一)
基于上一个后台进行服务发现的制作。
- eureka-server作为eureka的服务端,提供注册服务,其他的client作为eureka的客户端,属于一个应用,注册到eureka注册中心。
创建一个eureka-server提供注册服务





开始注册服务
去springboot服务端中去进行eureka的注册服务


eureka.client.service-url.defaultZone=http://127.0.0.1:1111/eureka/
spring.application.name=xxxServer
先启动eureka-serve提供注册服务,再重启springboot

- 看到springboot的服务注册到了eureka中
注册一个服务转发





<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka</artifactId>
</dependency>

eureka.client.service-url.defaultZone=http://127.0.0.1:1111/eureka/
spring.application.name=zlwCosume



- 发现成功调用了springboot中的服务的接口
eureka的结构

Eureka是个注册表,启动服务注册到上面去。SpringBoot启动后注册到Eureka,Consume启动后也注册到Eureka,Consume访问springboot的时候 实际是从Eureka找到Springboot的ip,然后调用的。
这里会从Eureka找到 对应服务的ip和端口号 才能完成访问

如果没有Eureka那么 这步是完成不了的 consume找不到对应的ip和端口号无法访问服务
这个操作就是 先去Eureka查找这个zlwServer的 (ip和端口),后续直接调用
那么这个是有个缓存期限的,找到zlwServer缓存一段时间 过一段时间再去Eureka查找
所以Eureka挂掉之后 隔一段时间 这个访问就报错了


注册,相当于工商局,你在工商局注册了一个公司,别人只要知道公司名就能找到你,后续操作 跟工商局就没关系了

