提交 4bc5eb23 编写于 作者: M ManongJu

服务注册监听器/开发环境下移除服务的设置

上级 8ec0fe1e
......@@ -21,7 +21,10 @@
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
......
......@@ -5,7 +5,23 @@ spring:
name: hello-service
eureka:
instance:
hostname: hello-service #ָEurekaʵ
hostname: hello-service #指定该Eureka实例的主机名
instance-id: ${spring.cloud.client.ipAddress}:${server.port}
###开发环境设置如下可快速移除不可用的服务
lease-renewal-interval-in-seconds: 5 #续约更新时间间隔(默认30秒)
lease-expiration-duration-in-seconds: 10 #续约到期时间(默认90秒)
client:
service-url:
defaultZone: http://register1:9010/eureka/,http://register2:9011/eureka/
\ No newline at end of file
defaultZone: http://register1:9010/eureka/,http://register2:9011/eureka/
###actuator监控点 start####
endpoints:
health:
sensitive: false
##默认情况下很多端点是不允许访问的,会返回401:Unauthorized
management:
security:
enabled: false
###actuator监控点 end####
......@@ -20,6 +20,10 @@
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka-server</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
......
package com.microservice.skeleton.register.listener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.netflix.eureka.server.event.EurekaInstanceCanceledEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.context.annotation.Configuration;
/**
* Created by Mr.Yangxiufeng on 2017/12/9.
* Time:13:45
* ProjectName:Mirco-Service-Skeleton
*/
@Configuration
public class InstanceCancelListener implements ApplicationListener<EurekaInstanceCanceledEvent> {
private static final Logger LOGGER = LoggerFactory.getLogger(InstanceCancelListener.class);
@Override
public void onApplicationEvent(EurekaInstanceCanceledEvent event) {
LOGGER.info("服务:{}挂了",event.getAppName());
}
}
package com.microservice.skeleton.register.listener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.netflix.eureka.server.event.EurekaInstanceRegisteredEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.context.annotation.Configuration;
/**
* Created by Mr.Yangxiufeng on 2017/12/9.
* Time:13:37
* ProjectName:Mirco-Service-Skeleton
*/
@Configuration
public class InstanceRegisterListener implements ApplicationListener<EurekaInstanceRegisteredEvent>{
private static final Logger LOGGER = LoggerFactory.getLogger(InstanceRegisterListener.class);
@Override
public void onApplicationEvent(EurekaInstanceRegisteredEvent eurekaInstanceRegisteredEvent) {
LOGGER.info("服务:{},注册成功了",eurekaInstanceRegisteredEvent.getInstanceInfo().getAppName());
}
}
package com.microservice.skeleton.register.listener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.netflix.eureka.server.event.EurekaInstanceRenewedEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.context.annotation.Configuration;
/**
* Created by Mr.Yangxiufeng on 2017/12/9.
* Time:13:48
* ProjectName:Mirco-Service-Skeleton
*/
@Configuration
public class InstanceRenewListener implements ApplicationListener<EurekaInstanceRenewedEvent> {
private static final Logger LOGGER = LoggerFactory.getLogger(InstanceRenewListener.class);
@Override
public void onApplicationEvent(EurekaInstanceRenewedEvent event) {
LOGGER.info("心跳检测服务:{}" ,event.getInstanceInfo().getAppName());
}
}
......@@ -10,4 +10,16 @@ eureka:
register-with-eureka: false
fetch-registry: false
service-url:
defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/
\ No newline at end of file
defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/
server:
eviction-interval-timer-in-ms: 5000 ## 清理间隔(单位毫秒,默认是60*1000),开发环境设置如下可快速移除不可用的服务
###actuator监控点 start####
endpoints:
health:
sensitive: false
enabled: true
##默认情况下很多端点是不允许访问的,会返回401:Unauthorized
management:
security:
enabled: false
###actuator监控点 end####
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册