通过eureka监听服务状态,发送预警邮件

Eureka的server端会发出5个事件通知,分别是:

EurekaInstanceCanceledEvent 服务下线事件
EurekaInstanceRegisteredEvent 服务注册事件
EurekaInstanceRenewedEvent 服务续约事件
EurekaRegistryAvailableEvent Eureka注册中心启动事件

EurekaServerStartedEvent Eureka Server启动事件


@Component
public class EurekaStateChangeListener {

    @Autowired
    private EmailLogService emailLogService;

    @EventListener
    public void listen(EurekaInstanceCanceledEvent eurekaInstanceCanceledEvent) {

        String appName = eurekaInstanceCanceledEvent.getAppName();
        String serverId = eurekaInstanceCanceledEvent.getServerId();
        System.out.println(appName);
        System.out.println(serverId);
        String message = LocalDateTime.now()+"\r\n"+appName+"\r\n"+serverId;
        emailLogService.sendMail(message);

    }
}

阅读更多

没有更多推荐了,返回首页