We have previously introduced the use of Spring Boot Admin to detect the upper and lower lines of the service, and then the notification function.
Article: http://cxytiandi.com/blog/detail/13376
Today we will introduce another way of implementation, in the Eureka Service for detection notification, Eureka provides the way to monitor the event to support the extension. Eurekainstancecanceledevent Service downline Event eurekainstanceregisteredevent Service registration Event Eurekainstancerenewedevent Service Renewal Event Eurekaregistryavailableevent Eureka Registry Start Event eurekaserverstartedevent Eureka Server Startup event
Import Com.netflix.appinfo.InstanceInfo;
Import org.springframework.cloud.netflix.eureka.server.event.*;
Import Org.springframework.context.event.EventListener;
Import org.springframework.stereotype.Component; /** * Eureka Event Monitoring * * @author Yinjihuan * @create 2018-03-09 13:45 **/@Component public class Eurekastatechangelisten ER {@EventListener public void Listen (Eurekainstancecanceledevent event) {System.err.println (event.gets
Erverid () + "\ T" + event.getappname () + "service downline"); } @EventListener public void Listen (Eurekainstanceregisteredevent event) {Instanceinfo instanceinfo = Ev
Ent.getinstanceinfo ();
System.err.println (Instanceinfo.getappname () + "register"); } @EventListener public void Listen (Eurekainstancerenewedevent event) {System.err.println (event.getserve
RId () + "\ T" + event.getappname () + "Service for Renewal"); } @EventListener public void Listen (Eurekaregistryavailableevent event) {SYSTEM.ERR.PRINTLN ("Registration center launch"); } @EventListener public void Listen (Eurekaserverstartedevent event) {System.err.println ("Eureka Server
Dynamic "); }
}
The above is just a demonstration of the effect of the event, specifically in what events need to do what action, need to send e-mail or text messages, you need to implement their own.
Note: In the Eureka cluster environment, each node will trigger the event, this time need to control the behavior of sending notifications, each node will send a notification without control.