org.zodiac.actuate.health.AppHealthIndicatorReactiveAdapter Maven / Gradle / Ivy
package org.zodiac.actuate.health;
import org.springframework.boot.actuate.health.Health;
import org.springframework.boot.actuate.health.HealthIndicator;
import org.springframework.util.Assert;
import reactor.core.publisher.Mono;
import reactor.core.publisher.MonoSink;
import reactor.core.scheduler.Schedulers;
public class AppHealthIndicatorReactiveAdapter implements AppReactiveHealthIndicator {
private final HealthIndicator delegate;
public AppHealthIndicatorReactiveAdapter(HealthIndicator delegate) {
Assert.notNull(delegate, "Delegate must not be null");
this.delegate = delegate;
}
@Override
public Mono health() {
return Mono.create((sink) -> Schedulers.elastic().schedule(() -> invoke(sink)));
}
private void invoke(MonoSink sink) {
try {
Health health = this.delegate.health();
sink.success(health);
} catch (Exception ex) {
sink.error(ex);
}
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy