标签:连接 如何 turn 新建 其它 when interval IV lease
最近在忙一些其它的事情,两个城市来回跑还要办一些手续,挺费劲的,学习的事情也就耽误了一些,尽量赶吧。
<parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.5.9.RELEASE</version> <relativePath/> </parent> <dependencyManagement> <dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-dependencies</artifactId> <version>Dalston.SR1</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-actuator</artifactId> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-eureka-server</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> </dependencies>
pom文件中,parent信息用于继承spring boot的基础默认配置,这个spring boot的parent实际是个空项目,只有一个pom文件,包含一些版本号等信息;dependencyManagement是用于描述Spring cloud所依赖的版本信息;因为spring boot跟spring cloud版本有对应关系,不能随意匹配版本;还有要注意的是此处eureka的依赖为eureka-server,不是starter,starter是用于客户端的jar包。
spring: application: name: eureka-server
#服务的描述信息,可以填写服务描述,责任联系人等信息 info: name: Eureka server contact: eureka 服务器 server: port: 8761 eureka: client: #是否注册到eureka server registerWithEureka: true #是否从服务器获取信息 fetchRegistry: false #eureka server地址 serviceUrl: defaultZone: http://127.0.0.1:8761/eureka/ server: #获取不到集群里对等服务器上的实例时,需要等待的时间,单位毫秒 waitTimeInMsWhenSyncEmpty: 0 #开启自我保护,无论如何都要剔除心跳检测异常的服务 enableSelfPreservation: true #updatePeerEurekaNodes执行间隔时间,集群信息刷新间隔时间 peerEurekaNodesUpdateIntervalMs: 100000
@SpringBootApplication @EnableEurekaServer public class MyEurekaApplication { public static void main(String[] args) { SpringApplication.run(MyEurekaApplication.class, args); } }
<dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-eureka</artifactId> </dependency>
spring: application: name: sms-module
info: name: author:wzy,class:develop,tel:17301394307 server: port: 9003 eureka: client: registerWithEureka: true fetchRegistry: true serverUrl: defaultZone: http://127.0.0.1:8761/eureka instance: #心跳间隔 leaseRenewalIntervalInSeconds: 10
@EnableEurekaClient @SpringBootApplication public class SmsApplication { public static void main(String[] args) { SpringApplication.run(SmsApplication.class, args); } }
3、消费者搭建
@RequestMapping("/mytest") @RestController public class TestController { @Autowired DiscoveryClient discoveryClient; @RequestMapping("/test") public String test(){ List<ServiceInstance> instanceList = discoveryClient.getInstances("sms-module"); StringBuffer sb = new StringBuffer(); for(int i=0; i<instanceList.size(); i++){ ServiceInstance instance = instanceList.get(i); String host = instance.getHost(); int port = instance.getPort(); String result = new RestTemplate().getForObject("http://"+host+":"+port+"/sms/sendmsg",String.class); sb.append(result+","); } return sb.toString(); } }
标签:连接 如何 turn 新建 其它 when interval IV lease
原文地址:https://www.cnblogs.com/nevermorewang/p/9164928.html