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的服务,用于定位服务,以实现云端中间层服务发现和故障转移.服务注册与发现对于微服务架构 ...
随机推荐
- HTTP六大请求
标准Http协议支持六种请求方法,即: 1.GET 2.POST 3.PUT 4.Delete 5.HEAD 6.Options 但其实我们大部分情况下只用到了GET和POST.如果想设计一个符合RE ...
- could not stop cortex-m device
检查一下STM32复位管脚是不是0V,如果是0V的话并且你有上拉电阻,那么就断电后检查一下STM32的VCC和GND是否短路,我的就是两个贴片电容击穿造成的短路从而使RST无法拉高.
- Git 学习第二天(一)
继续昨天的学习. 回顾一下,昨天我们安装了git 并创建了登录名及邮箱,还向git仓库提交了一个readme.txt的文本文件 下面,我们来修改下这个文件,将内容改为 Git is a distrib ...
- 剑指offer——74求1+2+3+n
题目描述 求1+2+3+...+n,要求不能使用乘除法.for.while.if.else.switch.case等关键字及条件判断语句(A?B:C). 题解: 利用类的构造和析构 //利用类的构 ...
- 剑指offer——40字符串的排列
题目描述 输入一个字符串,按字典序打印出该字符串中字符的所有排列.例如输入字符串abc,则打印出由字符a,b,c所能排列出来的所有字符串abc,acb,bac,bca,cab和cba. 输入描述: 输 ...
- Netty 源码学习——EventLoop
Netty 源码学习--EventLoop 在前面 Netty 源码学习--客户端流程分析中我们已经知道了一个 EventLoop 大概的流程,这一章我们来详细的看一看. NioEventLoopGr ...
- Django框架(十二)—— 补充:inclusion_tag、defer、only、choice、事务、创建多对多的第三张表
目录 补充:inclusion_tag.defer.only.choice.事务.创建多对多的第三张表 一.inclusion_tag 1.作用 2.使用 二.defer与only 1.定义 2.使用 ...
- CentOS7 网卡配置文件解释
注:此网卡配置文件摘自CentOS7.4.1708系统 Linux 默认配置网卡的信息 TYPE=Ethernet 网卡类型:以太网 PROXY_METHOD=none 代理方式:关闭状态 BROWS ...
- JQuery on绑定click无效的的bug解决办法?
如果你在移动端使用zepto.js, touch 来代替click事件,那就没有上述标题的问题了.如果你仍然使用了click,在点击事件中苹果机就可能出现无效的结果. 第一种方法: 解决的方法很巧妙, ...
- docker容器和宿主机时间不一致的问题
第1种:复制宿主机的localtime文件,到容器里docker cp /etc/localtime threg:/etc/ 注:这里 threg为容器名称,复制完后需重启容器 第2种在构建docke ...