All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.quarkus.grpc.runtime.health.GrpcHealthEndpoint Maven / Gradle / Ivy

There is a newer version: 3.15.1
Show newest version
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();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy