springcloud eureka server 检测 eureka client 状态
import com.netflix.discovery.shared.Applications;
import com.netflix.eureka.EurekaServerContextHolder;
import com.netflix.eureka.registry.PeerAwareInstanceRegistry;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.netflix.eureka.server.event.EurekaInstanceCanceledEvent;
import org.springframework.cloud.netflix.eureka.server.event.EurekaInstanceRegisteredEvent;
import org.springframework.cloud.netflix.eureka.server.event.EurekaInstanceRenewedEvent;
import org.springframework.cloud.netflix.eureka.server.event.EurekaRegistryAvailableEvent;
import org.springframework.context.ApplicationEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling; import java.util.Objects; /**
* Created with IDEA
* EurekaInstanceCanceledEvent 服务下线事件
* EurekaInstanceRegisteredEvent 服务注册事件
* EurekaInstanceRenewedEvent 服务续约事件
* EurekaRegistryAvailableEvent Eureka注册中心启动事件
* EurekaServerStartedEvent Eureka Server启动事件
*
* @author zhaowb
* @date 2018/11/20 20:37
*/
@Configuration
@EnableScheduling
public class EurekaInstanceCanceledListener implements ApplicationListener { private static final Logger log = LoggerFactory.getLogger(EurekaInstanceCanceledListener.class); @Override
public void onApplicationEvent(ApplicationEvent applicationEvent) {
//服务挂掉自动通知
if (applicationEvent instanceof EurekaInstanceCanceledEvent) {
EurekaInstanceCanceledEvent event = (EurekaInstanceCanceledEvent) applicationEvent;
//服务挂掉自动通知
PeerAwareInstanceRegistry registry = EurekaServerContextHolder.getInstance().getServerContext().getRegistry();
Applications applications = registry.getApplications(); // 获取已注册节点中和当前失效节ID点一直的节点信息
applications.getRegisteredApplications().forEach(registryApplication -> {
registryApplication.getInstances().forEach(instanceInfo -> {
if (Objects.equals(instanceInfo.getInstanceId(), event.getServerId())) {
log.info("服务:{}挂掉了。。。", event.getAppName());
// TODO
log.info("发送邮件到维护人员邮箱");
}
});
});
} if (applicationEvent instanceof EurekaInstanceRegisteredEvent) {
EurekaInstanceRegisteredEvent event = (EurekaInstanceRegisteredEvent) applicationEvent;
log.info("服务:{}注册成功。。。。。。", event.getInstanceInfo().getAppName());
}
if (applicationEvent instanceof EurekaInstanceRenewedEvent) {
EurekaInstanceRenewedEvent event = (EurekaInstanceRenewedEvent) applicationEvent;
log.info("服务:{} 心跳检测成功。。。。。", event.getInstanceInfo().getAppName());
}
if (applicationEvent instanceof EurekaRegistryAvailableEvent) {
log.info("服务 Available...");
}
}
}
springcloud eureka server 检测 eureka client 状态的更多相关文章
- Spring Cloud Eureka(三):认识Eureka Server 与 Eureka Client
Spring Cloud Netflix 是什么 This project provides Netflix OSS integrations for Spring Boot apps through ...
- 【SpringCloud】04.SpringCloud Eureka Server与Client的创建
Eureka是Netflix开发的服务发现框架,本身是一个基于REST的服务,主要用于定位运行在AWS域中的中间层服务,以达到负载均衡和中间层服务故障转移的目的.SpringCloud将它集成在其子项 ...
- SpringCloud系列三:将微服务注册到Eureka Server上
1. 回顾 通过上篇博客的讲解,我们知道硬编码提供者地址的方式有不少问题.要想解决这些问题,服务消费者需要一个强大的服务发现机制,服务消费者使用这种机制获取服务提供者的网络信息.不仅如此,即使服务提供 ...
- 【转载】一起来学Spring Cloud | Eureka Client注册到Eureka Server的秘密
LZ看到这篇文章感觉写得比较详细,理解以后,便转载到自己博客中,留作以后回顾学习用,喝水不忘挖井人,内容来自于李刚的博客:http://www.spring4all.com/article/180 一 ...
- SpringCloud系列四:实现Eureka Server的高可用并将应用注册到Eureka Sever集群上
1. 回顾 上一篇博客中,实现了单节点的Eureka Server.Eureka Client会定时连接Eureka Server,获取注册表中的信息并缓存到本地.微服务在消费远程API时总是使用本地 ...
- SpringCloud基础概念学习笔记(Eureka、Ribbon、Feign、Zuul)
SpringCloud基础概念学习笔记(Eureka.Ribbon.Feign.Zuul) SpringCloud入门 参考: https://springcloud.cc/spring-cloud- ...
- SpringCloud系列六:Eureka的自我保护模式、IP选择、健康检查
1. 回顾 前面讲了很多Eureka的用法,比如Eureka Server.Eureka Server的高可用.Eureka Server的用户认证(虽然未完全实现).元数据等, 这章将讲解剩下的自我 ...
- Spring Cloud Eureka源码分析 --- client 注册流程
Eureka Client 是一个Java 客户端,用于简化与Eureka Server的交互,客户端同时也具备一个内置的.使用轮询负载算法的负载均衡器. 在应用启动后,将会向Eureka Serve ...
- SpringCloud与微服务Ⅴ --- Eureka服务注册与发现
一.Eureka是什么 Eureka是Netflix的一个子模块,也是核心模块之一.Eureka是一个基于REST的服务,用于定位服务,以实现云端中间层服务发现和故障转移.服务注册与发现对于微服务架构 ...
随机推荐
- 介绍Win7 win8 上Java环境的配置
① windows 上的 java 环境搭建:(同时适合xp,vasta,win7,win8,win8.1) ② linux 上的java环境搭建(同时适合linux,unix,mac): 本文主要适 ...
- 【转载】Jmeter业务请求比例1
ps:文章转自订阅号“测试那点事儿”,链接:https://mp.weixin.qq.com/s/qVD4iNO0QqRIwAIq9_E_Kw 在进行综合场景压测时,由于不同的请求,要求所占比例不同, ...
- react map循环数据 死循环
项目条件:react es6 antidesign 已在commonState中获取到list,但是在循环map填充DOM的时候陷入死循环. 原因:因为是子组件 ,在父组件请求数据的时候 有个时差过程 ...
- arguments的使用
当我们不确定有多少参数传递的时候,可以使用 arguments 来获取,在 JavaScript 中, arguments 实际上它是当前函数的一个内置对象. 所有的函数都内置了一个 argument ...
- BBS论坛 文章详情、点赞、评论
六.文章详情.点赞.评论 文章详情页面: def article_detail(request, username, article_id): # user_obj = models.UserInfo ...
- 明年将制定个人信息保护法 网站部署https迫在眉睫
12月20日,全国人大常委会法工委举行第三次记者会.全国人大常委会法工委发言人岳仲明表示,中国明年将制定个人信息保护法.数据安全法等. 数据泄露为何频频出现 你是否经常接到骚扰电话?推销.诈骗等等均有 ...
- javascript 跨域问题 jsonp
转载:http://www.cnblogs.com/choon/p/5393682.html demo 用动态创建<script></script>节点的方式实现了跨域HTTP ...
- 如何在Windows10操作系统下安装superset步骤分享
superset是一个轻量级自助式BI框架,以优雅的界面和根据数据表动态生成数据为主要特点. 一. 环境 windows 10 64位 Python 3.7 二. 安装步骤 安装Python 建议安装 ...
- idea bug解决
1.编译时错误:软件包 javax.servlet.http 不存在import javax.servlet.http.HttpServletRequest 解决办法:把servlet-api.jar ...
- string的find("")
); string strleft; int FindMin = TempRangeData1.find(("_")); ) { strleft = (TempRangeData1 ...