use of org.springframework.cloud.netflix.eureka.server.event.EurekaRegistryAvailableEvent in project spring-boot by Linda-Tan.
the class EurekaInstanceCanceledListener method onApplicationEvent.
@Override
public void onApplicationEvent(ApplicationEvent applicationEvent) {
// 服务挂掉自动通知
if (applicationEvent instanceof EurekaInstanceCanceledEvent) {
EurekaInstanceCanceledEvent event = (EurekaInstanceCanceledEvent) applicationEvent;
// 获取当前Eureka示例中的节点信息
PeerAwareInstanceRegistry registry = EurekaServerContextHolder.getInstance().getServerContext().getRegistry();
Applications applications = registry.getApplications();
// 便利获取已注册节点中与当前失效节点ID一致 的节点信息
applications.getRegisteredApplications().forEach(registryApplication -> {
registryApplication.getInstances().forEach(instance -> {
if (Objects.equals(instance.getInstanceId(), event.getServerId())) {
log.info("服务:{}挂啦。。。", instance.getAppName());
// emailService.send(new SimpleMailMessage());
}
});
});
}
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。。。");
}
}
use of org.springframework.cloud.netflix.eureka.server.event.EurekaRegistryAvailableEvent in project spring-cloud-netflix by spring-cloud.
the class EurekaServerInitializerConfiguration method start.
@Override
public void start() {
new Thread(new Runnable() {
@Override
public void run() {
try {
// TODO: is this class even needed now?
eurekaServerBootstrap.contextInitialized(EurekaServerInitializerConfiguration.this.servletContext);
log.info("Started Eureka Server");
publish(new EurekaRegistryAvailableEvent(getEurekaServerConfig()));
EurekaServerInitializerConfiguration.this.running = true;
publish(new EurekaServerStartedEvent(getEurekaServerConfig()));
} catch (Exception ex) {
// Help!
log.error("Could not initialize Eureka servlet context", ex);
}
}
}).start();
}
Aggregations