Search in sources :

Example 1 with EurekaRegistryAvailableEvent

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。。。");
    }
}
Also used : EurekaInstanceRenewedEvent(org.springframework.cloud.netflix.eureka.server.event.EurekaInstanceRenewedEvent) Applications(com.netflix.discovery.shared.Applications) EurekaInstanceCanceledEvent(org.springframework.cloud.netflix.eureka.server.event.EurekaInstanceCanceledEvent) EurekaRegistryAvailableEvent(org.springframework.cloud.netflix.eureka.server.event.EurekaRegistryAvailableEvent) PeerAwareInstanceRegistry(com.netflix.eureka.registry.PeerAwareInstanceRegistry) EurekaInstanceRegisteredEvent(org.springframework.cloud.netflix.eureka.server.event.EurekaInstanceRegisteredEvent)

Example 2 with EurekaRegistryAvailableEvent

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();
}
Also used : EurekaRegistryAvailableEvent(org.springframework.cloud.netflix.eureka.server.event.EurekaRegistryAvailableEvent) EurekaServerStartedEvent(org.springframework.cloud.netflix.eureka.server.event.EurekaServerStartedEvent)

Aggregations

EurekaRegistryAvailableEvent (org.springframework.cloud.netflix.eureka.server.event.EurekaRegistryAvailableEvent)2 Applications (com.netflix.discovery.shared.Applications)1 PeerAwareInstanceRegistry (com.netflix.eureka.registry.PeerAwareInstanceRegistry)1 EurekaInstanceCanceledEvent (org.springframework.cloud.netflix.eureka.server.event.EurekaInstanceCanceledEvent)1 EurekaInstanceRegisteredEvent (org.springframework.cloud.netflix.eureka.server.event.EurekaInstanceRegisteredEvent)1 EurekaInstanceRenewedEvent (org.springframework.cloud.netflix.eureka.server.event.EurekaInstanceRenewedEvent)1 EurekaServerStartedEvent (org.springframework.cloud.netflix.eureka.server.event.EurekaServerStartedEvent)1