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

rebue.wheel.vertx.guice.GrpcNettyGuiceModule Maven / Gradle / Ivy

The newest version!
package rebue.wheel.vertx.guice;

import java.util.LinkedHashMap;
import java.util.Map;

import com.google.inject.AbstractModule;
import com.google.inject.Provides;

import io.grpc.ManagedChannel;
import io.vertx.core.Vertx;
import io.vertx.core.json.JsonObject;
import io.vertx.grpc.VertxChannelBuilder;
import jakarta.inject.Named;
import jakarta.inject.Singleton;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class GrpcNettyGuiceModule extends AbstractModule {

    public GrpcNettyGuiceModule() {
        log.info("new GRpcNettyGuiceModule");
    }

    @Singleton
    @Provides
    Map getGrpcChannels(Vertx vertx, @Named("config") final JsonObject config) {
        log.info("GRpcNettyGuiceModule.getGRpcChannel");
        Map result   = new LinkedHashMap<>();
        final JsonObject            grpc     = config.getJsonObject("grpc");
        JsonObject                  channels = grpc.getJsonObject("channels");
        channels.forEach(item -> {
            String     key   = item.getKey();
            JsonObject value = (JsonObject) item.getValue();
            result.put(key, VertxChannelBuilder
                    .forAddress(vertx, value.getString("host"), value.getInteger("port"))
                    .usePlaintext()
                    .build());
        });
        return result;
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy