Search in sources :

Example 1 with GrpcServiceDefinition

use of net.devh.boot.grpc.server.service.GrpcServiceDefinition in project grpc-spring-boot-starter by yidongnan.

the class GrpcServerFactoryAutoConfiguration method nettyGrpcServerFactory.

// Then try the normal netty server
/**
 * Creates a GrpcServerFactory using the non-shaded netty. This is the fallback, if the shaded one is not present.
 *
 * @param properties The properties used to configure the server.
 * @param serviceDiscoverer The discoverer used to identify the services that should be served.
 * @param serverConfigurers The server configurers that contain additional configuration for the server.
 * @return The shadedNettyGrpcServerFactory bean.
 */
@ConditionalOnMissingBean(ShadedNettyGrpcServerFactory.class)
@Conditional(ConditionalOnInterprocessServer.class)
@ConditionalOnClass(name = { "io.netty.channel.Channel", "io.grpc.netty.NettyServerBuilder" })
@Bean
public NettyGrpcServerFactory nettyGrpcServerFactory(final GrpcServerProperties properties, final GrpcServiceDiscoverer serviceDiscoverer, final List<GrpcServerConfigurer> serverConfigurers) {
    log.info("Detected grpc-netty: Creating NettyGrpcServerFactory");
    final NettyGrpcServerFactory factory = new NettyGrpcServerFactory(properties, serverConfigurers);
    for (final GrpcServiceDefinition service : serviceDiscoverer.findGrpcServices()) {
        factory.addService(service);
    }
    return factory;
}
Also used : ShadedNettyGrpcServerFactory(net.devh.boot.grpc.server.serverfactory.ShadedNettyGrpcServerFactory) NettyGrpcServerFactory(net.devh.boot.grpc.server.serverfactory.NettyGrpcServerFactory) GrpcServiceDefinition(net.devh.boot.grpc.server.service.GrpcServiceDefinition) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) ConditionalOnClass(org.springframework.boot.autoconfigure.condition.ConditionalOnClass) Conditional(org.springframework.context.annotation.Conditional) ConditionalOnBean(org.springframework.boot.autoconfigure.condition.ConditionalOnBean) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) Bean(org.springframework.context.annotation.Bean)

Example 2 with GrpcServiceDefinition

use of net.devh.boot.grpc.server.service.GrpcServiceDefinition in project grpc-spring-boot-starter by yidongnan.

the class GrpcServerFactoryAutoConfiguration method inProcessGrpcServerFactory.

/**
 * Creates a GrpcServerFactory using the in-process-server, if a name is specified.
 *
 * @param properties The properties used to configure the server.
 * @param serviceDiscoverer The discoverer used to identify the services that should be served.
 * @return The shadedNettyGrpcServerFactory bean.
 */
@ConditionalOnProperty(prefix = "grpc.server", name = "in-process-name")
@Bean
public InProcessGrpcServerFactory inProcessGrpcServerFactory(final GrpcServerProperties properties, final GrpcServiceDiscoverer serviceDiscoverer) {
    log.info("'grpc.server.in-process-name' is set: Creating InProcessGrpcServerFactory");
    final InProcessGrpcServerFactory factory = new InProcessGrpcServerFactory(properties);
    for (final GrpcServiceDefinition service : serviceDiscoverer.findGrpcServices()) {
        factory.addService(service);
    }
    return factory;
}
Also used : InProcessGrpcServerFactory(net.devh.boot.grpc.server.serverfactory.InProcessGrpcServerFactory) GrpcServiceDefinition(net.devh.boot.grpc.server.service.GrpcServiceDefinition) ConditionalOnProperty(org.springframework.boot.autoconfigure.condition.ConditionalOnProperty) ConditionalOnBean(org.springframework.boot.autoconfigure.condition.ConditionalOnBean) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) Bean(org.springframework.context.annotation.Bean)

Example 3 with GrpcServiceDefinition

use of net.devh.boot.grpc.server.service.GrpcServiceDefinition in project hedera-mirror-node by hashgraph.

the class GrpcConfiguration method grpcServices.

@Bean
CompositeHealthContributor grpcServices(GrpcServiceDiscoverer grpcServiceDiscoverer, HealthStatusManager healthStatusManager) {
    Map<String, HealthIndicator> healthIndicators = new LinkedHashMap<>();
    for (GrpcServiceDefinition grpcService : grpcServiceDiscoverer.findGrpcServices()) {
        String serviceName = grpcService.getDefinition().getServiceDescriptor().getName();
        healthIndicators.put(serviceName, new GrpcHealthIndicator(healthStatusManager, serviceName));
    }
    return CompositeHealthContributor.fromMap(healthIndicators);
}
Also used : GrpcServiceDefinition(net.devh.boot.grpc.server.service.GrpcServiceDefinition) HealthIndicator(org.springframework.boot.actuate.health.HealthIndicator) LinkedHashMap(java.util.LinkedHashMap) Bean(org.springframework.context.annotation.Bean)

Example 4 with GrpcServiceDefinition

use of net.devh.boot.grpc.server.service.GrpcServiceDefinition in project grpc-spring-boot-starter by yidongnan.

the class GrpcServerFactoryAutoConfiguration method shadedNettyGrpcServerFactory.

// First try the shaded netty server
/**
 * Creates a GrpcServerFactory using the shaded netty. This is the recommended default for gRPC.
 *
 * @param properties The properties used to configure the server.
 * @param serviceDiscoverer The discoverer used to identify the services that should be served.
 * @param serverConfigurers The server configurers that contain additional configuration for the server.
 * @return The shadedNettyGrpcServerFactory bean.
 */
@ConditionalOnClass(name = { "io.grpc.netty.shaded.io.netty.channel.Channel", "io.grpc.netty.shaded.io.grpc.netty.NettyServerBuilder" })
@Conditional(ConditionalOnInterprocessServer.class)
@Bean
public ShadedNettyGrpcServerFactory shadedNettyGrpcServerFactory(final GrpcServerProperties properties, final GrpcServiceDiscoverer serviceDiscoverer, final List<GrpcServerConfigurer> serverConfigurers) {
    log.info("Detected grpc-netty-shaded: Creating ShadedNettyGrpcServerFactory");
    final ShadedNettyGrpcServerFactory factory = new ShadedNettyGrpcServerFactory(properties, serverConfigurers);
    for (final GrpcServiceDefinition service : serviceDiscoverer.findGrpcServices()) {
        factory.addService(service);
    }
    return factory;
}
Also used : ShadedNettyGrpcServerFactory(net.devh.boot.grpc.server.serverfactory.ShadedNettyGrpcServerFactory) GrpcServiceDefinition(net.devh.boot.grpc.server.service.GrpcServiceDefinition) ConditionalOnClass(org.springframework.boot.autoconfigure.condition.ConditionalOnClass) Conditional(org.springframework.context.annotation.Conditional) ConditionalOnBean(org.springframework.boot.autoconfigure.condition.ConditionalOnBean) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) Bean(org.springframework.context.annotation.Bean)

Example 5 with GrpcServiceDefinition

use of net.devh.boot.grpc.server.service.GrpcServiceDefinition in project grpc-spring-boot-starter by yidongnan.

the class AbstractGrpcServerFactoryTest method testConfigureServices.

/**
 * Tests {@link AbstractGrpcServerFactory#configureServices(ServerBuilder)}.
 */
@Test
void testConfigureServices() {
    final GrpcServerProperties properties = new GrpcServerProperties();
    properties.setReflectionServiceEnabled(false);
    final NettyGrpcServerFactory serverFactory = new NettyGrpcServerFactory(properties, emptyList());
    serverFactory.addService(new GrpcServiceDefinition("test1", ProtoReflectionService.class, ProtoReflectionService.newInstance().bindService()));
    serverFactory.addService(new GrpcServiceDefinition("test2", ProtoReflectionService.class, ProtoReflectionService.newInstance().bindService()));
    final NettyServerBuilder serverBuilder = serverFactory.newServerBuilder();
    assertEquals("Found duplicate service implementation: " + ServerReflectionGrpc.SERVICE_NAME, assertThrows(IllegalStateException.class, () -> serverFactory.configureServices(serverBuilder)).getMessage());
}
Also used : GrpcServiceDefinition(net.devh.boot.grpc.server.service.GrpcServiceDefinition) GrpcServerProperties(net.devh.boot.grpc.server.config.GrpcServerProperties) NettyServerBuilder(io.grpc.netty.NettyServerBuilder) ProtoReflectionService(io.grpc.protobuf.services.ProtoReflectionService) Test(org.junit.jupiter.api.Test)

Aggregations

GrpcServiceDefinition (net.devh.boot.grpc.server.service.GrpcServiceDefinition)7 Bean (org.springframework.context.annotation.Bean)4 ConditionalOnBean (org.springframework.boot.autoconfigure.condition.ConditionalOnBean)3 ConditionalOnMissingBean (org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean)3 GrpcServerProperties (net.devh.boot.grpc.server.config.GrpcServerProperties)2 InProcessGrpcServerFactory (net.devh.boot.grpc.server.serverfactory.InProcessGrpcServerFactory)2 ShadedNettyGrpcServerFactory (net.devh.boot.grpc.server.serverfactory.ShadedNettyGrpcServerFactory)2 ConditionalOnClass (org.springframework.boot.autoconfigure.condition.ConditionalOnClass)2 Conditional (org.springframework.context.annotation.Conditional)2 NettyServerBuilder (io.grpc.netty.NettyServerBuilder)1 ProtoReflectionService (io.grpc.protobuf.services.ProtoReflectionService)1 LinkedHashMap (java.util.LinkedHashMap)1 LinkedHashSet (java.util.LinkedHashSet)1 GrpcServerFactory (net.devh.boot.grpc.server.serverfactory.GrpcServerFactory)1 GrpcServerLifecycle (net.devh.boot.grpc.server.serverfactory.GrpcServerLifecycle)1 NettyGrpcServerFactory (net.devh.boot.grpc.server.serverfactory.NettyGrpcServerFactory)1 WaitingTestService (net.devh.boot.grpc.test.server.WaitingTestService)1 Test (org.junit.jupiter.api.Test)1 HealthIndicator (org.springframework.boot.actuate.health.HealthIndicator)1 ConditionalOnProperty (org.springframework.boot.autoconfigure.condition.ConditionalOnProperty)1