From 3ccd79c817eaedda7cef11d027d59e3fe1911e28 Mon Sep 17 00:00:00 2001 From: Kai Moritz Date: Tue, 5 Mar 2024 09:46:55 +0100 Subject: [PATCH] feat: Implemented and configured health-indicator for the ``Channel``s --- .../kafka/ChannelReactiveHealthIndicator.java | 29 +++++++++++++++++++ .../kafka/KafkaServicesConfiguration.java | 13 +++++++++ 2 files changed, 42 insertions(+) create mode 100644 src/main/java/de/juplo/kafka/chat/backend/implementation/kafka/ChannelReactiveHealthIndicator.java diff --git a/src/main/java/de/juplo/kafka/chat/backend/implementation/kafka/ChannelReactiveHealthIndicator.java b/src/main/java/de/juplo/kafka/chat/backend/implementation/kafka/ChannelReactiveHealthIndicator.java new file mode 100644 index 00000000..dcb6158d --- /dev/null +++ b/src/main/java/de/juplo/kafka/chat/backend/implementation/kafka/ChannelReactiveHealthIndicator.java @@ -0,0 +1,29 @@ +package de.juplo.kafka.chat.backend.implementation.kafka; + +import lombok.RequiredArgsConstructor; +import org.springframework.boot.actuate.health.AbstractReactiveHealthIndicator; +import org.springframework.boot.actuate.health.Health; +import reactor.core.publisher.Mono; + + +@RequiredArgsConstructor +public class ChannelReactiveHealthIndicator extends AbstractReactiveHealthIndicator +{ + private final Channel channel; + + + @Override + protected Mono doHealthCheck(Health.Builder builder) + { + return Mono + .fromSupplier(() -> channel.getChannelState()) + .map(state -> switch(state) + { + case STARTING -> builder.outOfService(); + case LOAD_IN_PROGRESS -> builder.outOfService(); + case READY -> builder.up(); + case SHUTTING_DOWN -> builder.down(); + }) + .map(healthBuilder -> healthBuilder.build()); + } +} diff --git a/src/main/java/de/juplo/kafka/chat/backend/implementation/kafka/KafkaServicesConfiguration.java b/src/main/java/de/juplo/kafka/chat/backend/implementation/kafka/KafkaServicesConfiguration.java index c7cf113a..525c427a 100644 --- a/src/main/java/de/juplo/kafka/chat/backend/implementation/kafka/KafkaServicesConfiguration.java +++ b/src/main/java/de/juplo/kafka/chat/backend/implementation/kafka/KafkaServicesConfiguration.java @@ -314,4 +314,17 @@ public class KafkaServicesConfiguration { return ZoneId.systemDefault(); } + + @Bean + ChannelReactiveHealthIndicator dataChannelHealthIndicator( + DataChannel dataChannel) + { + return new ChannelReactiveHealthIndicator(dataChannel); + } + + @Bean + ChannelReactiveHealthIndicator infoChannelHealthIndicator(InfoChannel infoChannel) + { + return new ChannelReactiveHealthIndicator(infoChannel); + } } -- 2.20.1