use of org.springframework.cloud.netflix.eureka.server.event.EurekaInstanceCanceledEvent 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.EurekaInstanceCanceledEvent in project spring-cloud-netflix by spring-cloud.
the class InstanceRegistryTests method testInternalCancel.
@Test
public void testInternalCancel() throws Exception {
// calling tested method
instanceRegistry.internalCancel(APP_NAME, HOST_NAME, false);
// event of proper type is registered
assertEquals(1, this.testEvents.applicationEvents.size());
assertTrue(this.testEvents.applicationEvents.get(0) instanceof EurekaInstanceCanceledEvent);
// event details are correct
final EurekaInstanceCanceledEvent registeredEvent = (EurekaInstanceCanceledEvent) (this.testEvents.applicationEvents.get(0));
assertEquals(APP_NAME, registeredEvent.getAppName());
assertEquals(HOST_NAME, registeredEvent.getServerId());
assertEquals(instanceRegistry, registeredEvent.getSource());
assertFalse(registeredEvent.isReplication());
}
use of org.springframework.cloud.netflix.eureka.server.event.EurekaInstanceCanceledEvent in project spring-cloud-netflix by spring-cloud.
the class InstanceRegistry method handleCancelation.
private void handleCancelation(String appName, String id, boolean isReplication) {
log("cancel " + appName + ", serverId " + id + ", isReplication " + isReplication);
publishEvent(new EurekaInstanceCanceledEvent(this, appName, id, isReplication));
}
Aggregations