服务注册与发现---spring cloud

Eureka基本架构
Register Service :服务注册中心,它是一个 Eureka Server ,提供服务注册和发现的功能。
Provider Service :服务提供者,它是 Eureka Client ,提供服务
Consumer Service :服务消费者,它是 Eureka Cient ,消费服务
测试代码
1.服务端
appliation.yml
server :
port : 8761
eureka :
instance :
hostname : localhost
client :
registerWithEureka: false
fetchReg stry false
servi ceUrl :
defaultZone :
http://$(eureka instance hostname ♀( server port)/eureka/

@EnableEurekaServer
@SpringBootApplication
public class EurekaServerApplication (
public stat VO mai 口( String [] args) (
SpringApplication run(EurekaServerApplicatio class args) ;
}
}

2.客户端
application.yml配置文件

eureka:
client :
serviceUrl:
defaultZone : http://localhost:8761/eureka/
server:
port : 8762
spring :
application :
name . eureka-client

@SpringBootApplication
@EnableEurekaClient
public class EurekaClientApplication{
public static void main (String [] args) (
SpringApplication.run(EurekaClientApplication . class, args);
}
}

@RestController
public class HiController {
@Value (”${ server.port)”)
String port;
@GetMapping (”/ hi”)
public String home (@RequestParam String name) {
return ” hi ”+name+”, l am from port : ” +port;
}
}

3.Eureka 的一些概念
服务注册,服务续约,获取服务注册列表,服务下线,服务剔除

原文地址:https://www.cnblogs.com/dibinbin/p/9263620.html