From 7487c92a523ae979f8fc1875b129c64f3b5f12e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=96=AF=E7=8B=82=E7=9A=84=E7=8B=AE=E5=AD=90Li?= <15040126243@163.com> Date: Sun, 9 Jan 2022 00:54:59 +0800 Subject: [PATCH] =?UTF-8?q?add=20=E5=A2=9E=E5=8A=A0=20=E7=9B=91=E6=8E=A7?= =?UTF-8?q?=E4=B8=AD=E5=BF=83=20=E8=87=AA=E5=AE=9A=E4=B9=89=E4=BA=8B?= =?UTF-8?q?=E4=BB=B6=E9=80=9A=E7=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ruoyi-extend/ruoyi-monitor-admin/pom.xml | 5 +++ .../admin/notifier/CustomNotifier.java | 40 +++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 ruoyi-extend/ruoyi-monitor-admin/src/main/java/com/ruoyi/monitor/admin/notifier/CustomNotifier.java diff --git a/ruoyi-extend/ruoyi-monitor-admin/pom.xml b/ruoyi-extend/ruoyi-monitor-admin/pom.xml index 4b0d591c..e21cc6da 100644 --- a/ruoyi-extend/ruoyi-monitor-admin/pom.xml +++ b/ruoyi-extend/ruoyi-monitor-admin/pom.xml @@ -34,6 +34,11 @@ spring-boot-admin-starter-client + + org.projectlombok + lombok + + diff --git a/ruoyi-extend/ruoyi-monitor-admin/src/main/java/com/ruoyi/monitor/admin/notifier/CustomNotifier.java b/ruoyi-extend/ruoyi-monitor-admin/src/main/java/com/ruoyi/monitor/admin/notifier/CustomNotifier.java new file mode 100644 index 00000000..4d0a7a03 --- /dev/null +++ b/ruoyi-extend/ruoyi-monitor-admin/src/main/java/com/ruoyi/monitor/admin/notifier/CustomNotifier.java @@ -0,0 +1,40 @@ +package com.ruoyi.monitor.admin.notifier; + +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.AbstractEventNotifier; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Component; +import reactor.core.publisher.Mono; + +/** + * 自定义事件通知处理 + * + * @author Lion Li + */ +@Slf4j +@Component +public class CustomNotifier extends AbstractEventNotifier { + + protected CustomNotifier(InstanceRepository repository) { + super(repository); + } + + @Override + @SuppressWarnings("all") + protected Mono doNotify(InstanceEvent event, Instance instance) { + return Mono.fromRunnable(() -> { + // 实例状态改变事件 + if (event instanceof InstanceStatusChangedEvent) { + String registName = instance.getRegistration().getName(); + String instanceId = event.getInstance().getValue(); + String status = ((InstanceStatusChangedEvent) event).getStatusInfo().getStatus(); + log.info("Instance Status Change: [{}],[{}],[{}]", registName, instanceId, status); + } + + }); + } + +}