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的服务,用于定位服务,以实现云端中间层服务发现和故障转移.服务注册与发现对于微服务架构 ...
随机推荐
- hibernate5.2.10.Final基本配置
1.在官网去下载,解压后在lib/required目录下的所有jar包都是必要的. 2.为了之后配置方便,建议在eclipse里面安装一个东东,操作步骤是在eclipse->Help->I ...
- USACO2007 The Bale Tower /// DFS oj21160
题目大意: 给出N个捆包,每个捆包有相应的长度和宽度,要求堆叠捆包,使下方的捆包长宽永远大于上方的捆包的长宽. Input Multiple test case. For each case: * L ...
- WebServer Project-01-反射
简介 上网浏览网页,离不开服务器,客户请求页面,服务器响应页面,响应的内容是根据每个web请求来产生动态内容的,其内部即启动多个线程来产生不同内容.这种请求响应的交互,都是基于HTTP协议的. 当然现 ...
- 无法CREATE UNIQUE INDEX;找到重复的关键字
- DOM中常见的元素获取方式
1.getElementById获取元素 返回的是一个元素对象 var timer = document.getElementById('time'); console.dir 打印返回元 ...
- vue 单元素过渡
demo <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF- ...
- C#/.NET 实现的多屏联动,多屏共享,显示到指定屏幕上
假设我现在有4个屏幕,希望实现主屏幕在操作的时候,其他3块屏幕可以实时联动,并且延迟在1s以内. 正常情况下,我们可以借助于各个远程软件实现效果,但是有时候会显得笨重麻烦,假如只有一台服务器呢?? S ...
- [JZOJ6359] 【NOIP2019模拟2019.9.15】小ω的树
题目 题目大意 给你一棵树,带点权和边权. 要你选择一个联通子图,使得点权和乘最小边权最大. 支持修改点权操作. 思考历程 显然,最先想到的当然是重构树了-- 重构树就是在做最大生成树的时候,当两个联 ...
- 一起看下Apache1.3.22版本改进和修正了啥?
Apache 1.3.20 - 1.3.22主要改进: 安全弱点: 1.在Apache1.3.20的win32平台上发现了一个漏洞.如果客户端发送一个非常长的URI可能导致用目录列表来代替缺省主页.4 ...
- Jmeter-【JSON Extractor】-响应结果中一级key取值
一.请求返回样式 二.取code值 三.查看结果