org.lognet.springboot.grpc.autoconfigure.GRpcAutoConfiguration Maven / Gradle / Ivy
The newest version!
package org.lognet.springboot.grpc.autoconfigure;
import io.grpc.ServerBuilder;
import io.grpc.inprocess.InProcessServerBuilder;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.util.Collection;
import java.util.List;
import java.util.Optional;
import java.util.function.Consumer;
import org.lognet.springboot.grpc.FailureHandlingSupport;
import org.lognet.springboot.grpc.GRpcGlobalInterceptor;
import org.lognet.springboot.grpc.GRpcServerBuilderConfigurer;
import org.lognet.springboot.grpc.GRpcServerRunner;
import org.lognet.springboot.grpc.GRpcService;
import org.lognet.springboot.grpc.GRpcServicesRegistry;
import org.lognet.springboot.grpc.health.DefaultHealthStatusService;
import org.lognet.springboot.grpc.recovery.GRpcExceptionHandlerInterceptor;
import org.lognet.springboot.grpc.recovery.GRpcExceptionHandlerMethodResolver;
import org.lognet.springboot.grpc.recovery.GRpcServiceAdvice;
import org.springframework.beans.factory.BeanCreationException;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.AutoConfigureOrder;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.autoconfigure.validation.ValidationAutoConfiguration;
import org.springframework.boot.context.properties.ConfigurationPropertiesBindHandlerAdvisor;
import org.springframework.boot.context.properties.ConfigurationPropertiesBinding;
import org.springframework.boot.context.properties.bind.AbstractBindHandler;
import org.springframework.boot.context.properties.bind.BindContext;
import org.springframework.boot.context.properties.bind.Bindable;
import org.springframework.boot.context.properties.source.ConfigurationPropertyName;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.core.convert.converter.Converter;
/** Created by alexf on 25-Jan-16. */
@AutoConfigureOrder
@AutoConfigureAfter(ValidationAutoConfiguration.class)
@ConditionalOnBean(annotation = GRpcService.class)
@Import({
GRpcValidationConfiguration.class,
NettyServerBuilderSelector.class,
DefaultHealthStatusService.class
})
@Configuration
public class GRpcAutoConfiguration {
@Bean
@OnGrpcServerEnabled
public GRpcServerRunner grpcServerRunner(
@Qualifier("grpcInternalConfigurator") Consumer> configurator,
ServerBuilder> serverBuilder) {
return new GRpcServerRunner(configurator, serverBuilder);
}
@Bean
@ConditionalOnProperty(prefix = "grpc", name = "in-process-server-name")
public GRpcServerRunner grpcInprocessServerRunner(
@Qualifier("grpcInternalConfigurator") Consumer> configurator,
GRpcServerProperties gRpcServerProperties) {
return new GRpcServerRunner(
configurator,
InProcessServerBuilder.forName(gRpcServerProperties.getInProcessServerName()));
}
@Bean
public GRpcServicesRegistry grpcServicesRegistry() {
return new GRpcServicesRegistry();
}
@Bean
public GRpcExceptionHandlerMethodResolver exceptionHandlerMethodResolver(
GRpcServicesRegistry gRpcServicesRegistry, ApplicationContext applicationContext) {
final Collection