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;
}
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;
}
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);
}
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;
}
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());
}
Aggregations