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的服务,用于定位服务,以实现云端中间层服务发现和故障转移.服务注册与发现对于微服务架构 ...
随机推荐
- OpenLayers绘制图形
OpenLayers绘制图形 OpenLayers的显示构成由外向内为: ol.Map:地图对象. ol.layer.Vector:图层对象layer.Map含有多个layer,最终的显示效果是由 ...
- HTML a标签文字颜色
1.css代码: a{color:#00F} a:hover{color:#f00}/* 鼠标经过悬停字体颜色 */ /* css 注释说明:以上代码为设置HTML中超链接统一字体颜色 */ .div ...
- Codeforces 1172A Nauuo and Cards
题目链接:http://codeforces.com/problemset/problem/1172/A 题意:一共有2*n张牌,n张0,n张1到n.现在随机的n张(有0有数字)在手上,另n张再牌堆中 ...
- Java内存通道
对文件执行I/O的另一种方法是将文件的一个区域映射到物理内存,并将其作为内存数组.可以使用MappedByteBuffer来执行内存映射文件I/O. 要使用内存映射文件I/O,请为文件获取FileCh ...
- 用node-http-proxy搭建代理
程序员三大必备网站是:Google.Github.StackOverflow.如果你还在用Baidu搜索技术文章的话,我想说的是,少年你已经被鄙视很多年了,赶紧换成谷歌吧,不要再被鄙视了!Github ...
- JDK8新特性之Optional
Optional是什么 java.util.Optional Jdk8提供Optional,一个可以包含null值的容器对象,可以用来代替xx != null的判断. Optional常用方法 of ...
- 从零开始搭建系统1.5——Redis安装及配置
1.在/usr/目录下创建redis目录 [root@localhost usr]# mkdir redis 2.下载安装包 wget http://download.redis.io/release ...
- [转]WPF中的导航框架
有的时候,我们需要一个支持页面跳转的UI,例如文件浏览器,开始向导等.对于这样的界面,简单的可以使用ContentControl + ContentTemplateSelector的方式来实现,但是有 ...
- wordpress翻译插件gtranslate
https://www.gdstautoparts.com/
- 用jQuery,ajax,实现三级联动封装JS的文件
// JavaScript Document $(document).ready(function(e) { //找到ID=SANJI的DIV,造三个下拉扔进去 var str = "< ...