io.quarkus.grpc.runtime.health.GrpcHealthEndpoint Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of quarkus-grpc Show documentation
Show all versions of quarkus-grpc Show documentation
Serve and consume gRPC services
package io.quarkus.grpc.runtime.health;
import java.util.function.Function;
import java.util.function.Supplier;
import jakarta.inject.Inject;
import jakarta.inject.Singleton;
import grpc.health.v1.HealthOuterClass;
import grpc.health.v1.HealthOuterClass.HealthCheckResponse.ServingStatus;
import grpc.health.v1.MutinyHealthGrpc;
import io.quarkus.grpc.GrpcService;
import io.smallrye.mutiny.Multi;
import io.smallrye.mutiny.Uni;
import io.smallrye.mutiny.operators.multi.processors.BroadcastProcessor;
// Note that we need to add the scope explicitly because this class is not part of the index
@Singleton
@GrpcService
public class GrpcHealthEndpoint extends MutinyHealthGrpc.HealthImplBase {
@Inject
GrpcHealthStorage healthStorage;
@Override
public Uni check(HealthOuterClass.HealthCheckRequest request) {
return Uni.createFrom().item(healthStorage.statusForService(request.getService()));
}
@Override
public Multi watch(HealthOuterClass.HealthCheckRequest request) {
String service = request.getService();
BroadcastProcessor broadcastProcessor = healthStorage.createStatusBroadcastProcessor(service);
return Multi.createBy().concatenating().streams(
Multi.createFrom().item(new Supplier() {
@Override
public HealthOuterClass.HealthCheckResponse get() {
return healthStorage.statusForService(service);
}
}),
broadcastProcessor.map(new Function() {
@Override
public HealthOuterClass.HealthCheckResponse apply(ServingStatus servingStatus) {
return healthStorage.resultForStatus(servingStatus);
}
})).skip().repetitions();
}
}