1,依赖
<dependency> <groupId>de.codecentric</groupId> <artifactId>spring-boot-admin-starter-server</artifactId> <version>2.2.3</version> </dependency>
2,实现AbstractStatusChangeNotifier
import de.codecentric.boot.admin.server.domain.entities.Instance; import de.codecentric.boot.admin.server.domain.entities.InstanceRepository; import de.codecentric.boot.admin.server.domain.events.InstanceEvent; import de.codecentric.boot.admin.server.domain.events.InstanceStatusChangedEvent; import de.codecentric.boot.admin.server.notify.AbstractStatusChangeNotifier; import reactor.core.publisher.Mono; public class DingdingNotifier extends AbstractStatusChangeNotifier { public DingdingNotifier(InstanceRepository repository) { super(repository); } @Override protected boolean shouldNotify(InstanceEvent event, Instance instance) { if (event instanceof InstanceStatusChangedEvent) { return true; } return false; } @Override protected Mono<Void> doNotify(InstanceEvent event, Instance instance) { return Mono.fromRunnable(() -> { // createMessage(event, instance); } ); } }
3,将监听注入ioc容器
import cn.jiguang.anti.deception.monitor.notifier.DingTalkNotifier; import de.codecentric.boot.admin.server.config.AdminServerHazelcastAutoConfiguration; import de.codecentric.boot.admin.server.config.AdminServerNotifierAutoConfiguration; import de.codecentric.boot.admin.server.domain.entities.InstanceRepository; import org.springframework.boot.autoconfigure.AutoConfigureBefore; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; /** * @author yintp */ @Configuration @ConditionalOnProperty( prefix = "spring.boot.admin.notify.dingtalk", name = {"webhook-token"} ) @AutoConfigureBefore({AdminServerHazelcastAutoConfiguration.NotifierTriggerConfiguration.class, AdminServerNotifierAutoConfiguration.CompositeNotifierConfiguration.class}) public class DingTalkNotifierConfiguration { @Bean @ConditionalOnMissingBean @ConfigurationProperties(prefix = "spring.boot.admin.notify.dingtalk") public DingTalkNotifier dingTalkNotifier(InstanceRepository repository) { return new DingTalkNotifier(repository); } }