├── .gitattributes ├── .github ├── ISSUE_TEMPLATE │ ├── bug_report.md │ ├── feature_request.md │ └── question.md ├── renovate.json5 └── workflows │ ├── build-master.yml │ └── pull-request.yml ├── .gitignore ├── CONTRIBUTING.md ├── LICENSE ├── README-zh-CN.md ├── README.md ├── build.gradle ├── crowdin.yml ├── deploy.gradle ├── docs ├── _config.yml ├── assets │ ├── css │ │ └── style.scss │ └── images │ │ ├── client-project-setup.dot │ │ ├── client-project-setup.svg │ │ ├── server-project-setup.dot │ │ ├── server-project-setup.svg │ │ ├── server-security.graphml │ │ └── server-security.svg ├── en │ ├── actuator.md │ ├── benchmarking.md │ ├── brave.md │ ├── client │ │ ├── configuration.md │ │ ├── getting-started.md │ │ ├── security.md │ │ └── testing.md │ ├── contributions.md │ ├── examples.md │ ├── flavors.md │ ├── index.md │ ├── kubernetes.md │ ├── server │ │ ├── configuration.md │ │ ├── contextual-data.md │ │ ├── events.md │ │ ├── exception-handling.md │ │ ├── getting-started.md │ │ ├── security.md │ │ └── testing.md │ ├── trouble-shooting.md │ └── versions.md ├── index.md └── zh-CN │ ├── actuator.md │ ├── benchmarking.md │ ├── brave.md │ ├── client │ ├── configuration.md │ ├── getting-started.md │ ├── security.md │ └── testing.md │ ├── contributions.md │ ├── examples.md │ ├── flavors.md │ ├── index.md │ ├── kubernetes.md │ ├── server │ ├── configuration.md │ ├── contextual-data.md │ ├── events.md │ ├── exception-handling.md │ ├── getting-started.md │ ├── security.md │ └── testing.md │ ├── trouble-shooting.md │ └── versions.md ├── examples ├── README.md ├── cloud-eureka-server │ ├── build.gradle │ └── src │ │ └── main │ │ ├── java │ │ └── net │ │ │ └── devh │ │ │ └── boot │ │ │ └── grpc │ │ │ └── examples │ │ │ └── cloud │ │ │ └── server │ │ │ └── EurekaServerApplication.java │ │ └── resources │ │ └── application.yml ├── cloud-grpc-client │ ├── build.gradle │ └── src │ │ └── main │ │ ├── java │ │ └── net │ │ │ └── devh │ │ │ └── boot │ │ │ └── grpc │ │ │ └── examples │ │ │ └── cloud │ │ │ └── client │ │ │ ├── CloudClientApplication.java │ │ │ ├── GlobalInterceptorConfiguration.java │ │ │ ├── GrpcClientController.java │ │ │ ├── GrpcClientService.java │ │ │ └── LogGrpcInterceptor.java │ │ └── resources │ │ ├── application-consul.yml │ │ ├── application-eureka.yml │ │ ├── application-nacos.yml │ │ ├── application-zookeeper.yml │ │ └── application.yml ├── cloud-grpc-server │ ├── build.gradle │ └── src │ │ └── main │ │ ├── java │ │ └── net │ │ │ └── devh │ │ │ └── boot │ │ │ └── grpc │ │ │ └── examples │ │ │ └── cloud │ │ │ └── server │ │ │ ├── CloudServerApplication.java │ │ │ ├── GlobalInterceptorConfiguration.java │ │ │ ├── GrpcServerService.java │ │ │ └── LogGrpcInterceptor.java │ │ └── resources │ │ ├── application-consul.yml │ │ ├── application-eureka.yml │ │ ├── application-nacos.yml │ │ ├── application-zookeeper.yml │ │ └── application.yml ├── grpc-lib │ ├── build.gradle │ └── src │ │ └── main │ │ └── proto │ │ └── helloworld.proto ├── grpc-observability │ ├── README.md │ ├── backend │ │ ├── Dockerfile │ │ ├── backend.yaml │ │ ├── build.gradle │ │ └── src │ │ │ └── main │ │ │ ├── java │ │ │ └── net │ │ │ │ └── devh │ │ │ │ └── boot │ │ │ │ └── grpc │ │ │ │ └── examples │ │ │ │ └── observability │ │ │ │ └── backend │ │ │ │ ├── BackendApplication.java │ │ │ │ └── ExampleServiceImpl.java │ │ │ └── resources │ │ │ └── application.properties │ ├── frontend │ │ ├── Dockerfile │ │ ├── build.gradle │ │ ├── frontend.yaml │ │ └── src │ │ │ └── main │ │ │ ├── java │ │ │ └── net │ │ │ │ └── devh │ │ │ │ └── boot │ │ │ │ └── grpc │ │ │ │ └── examples │ │ │ │ └── observability │ │ │ │ └── frontend │ │ │ │ └── FrontendApplication.java │ │ │ └── resources │ │ │ └── application.properties │ ├── grafana │ │ └── prometheus │ │ │ └── microservices-grpc-dashboard.json │ ├── pod_monitoring.yaml │ └── proto │ │ ├── build.gradle │ │ └── src │ │ └── main │ │ └── proto │ │ └── backend.proto ├── local-grpc-client │ ├── build.gradle │ └── src │ │ └── main │ │ ├── java │ │ └── net │ │ │ └── devh │ │ │ └── boot │ │ │ └── grpc │ │ │ └── examples │ │ │ └── local │ │ │ └── client │ │ │ ├── GlobalClientInterceptorConfiguration.java │ │ │ ├── GrpcClientController.java │ │ │ ├── GrpcClientService.java │ │ │ ├── LocalGrpcClientApplication.java │ │ │ └── LogGrpcInterceptor.java │ │ └── resources │ │ └── application.yml ├── local-grpc-server │ ├── build.gradle │ └── src │ │ └── main │ │ ├── java │ │ └── net │ │ │ └── devh │ │ │ └── boot │ │ │ └── grpc │ │ │ └── examples │ │ │ └── local │ │ │ └── server │ │ │ ├── GlobalInterceptorConfiguration.java │ │ │ ├── GrpcServerService.java │ │ │ ├── LocalGrpcServerApplication.java │ │ │ └── LogGrpcInterceptor.java │ │ └── resources │ │ └── application.yml ├── security-grpc-client │ ├── build.gradle │ └── src │ │ └── main │ │ ├── java │ │ └── net │ │ │ └── devh │ │ │ └── boot │ │ │ └── grpc │ │ │ └── examples │ │ │ └── security │ │ │ └── client │ │ │ ├── GrpcClientController.java │ │ │ ├── GrpcClientService.java │ │ │ ├── SecurityConfiguration.java │ │ │ └── SecurityGrpcClientApplication.java │ │ └── resources │ │ └── application.yml └── security-grpc-server │ ├── build.gradle │ └── src │ └── main │ ├── java │ └── net │ │ └── devh │ │ └── boot │ │ └── grpc │ │ └── examples │ │ └── security │ │ └── server │ │ ├── GrpcServerService.java │ │ ├── SecurityConfiguration.java │ │ └── SecurityGrpcServerApplication.java │ └── resources │ └── application.yml ├── extra ├── eclipse │ ├── eclipse-formatter.xml │ └── eclipse.importorder └── spotless │ └── license.java ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── grpc-client-spring-boot-starter ├── build.gradle └── src │ ├── main │ ├── java │ │ └── net │ │ │ └── devh │ │ │ └── boot │ │ │ └── grpc │ │ │ └── client │ │ │ ├── autoconfigure │ │ │ ├── GrpcClientAutoConfiguration.java │ │ │ ├── GrpcClientDefaultRequestTimeoutAutoConfiguration.java │ │ │ ├── GrpcClientHealthAutoConfiguration.java │ │ │ ├── GrpcClientMetricAutoConfiguration.java │ │ │ ├── GrpcClientMicrometerTraceAutoConfiguration.java │ │ │ ├── GrpcClientSecurityAutoConfiguration.java │ │ │ ├── GrpcDiscoveryClientAutoConfiguration.java │ │ │ └── package-info.java │ │ │ ├── channelfactory │ │ │ ├── AbstractChannelFactory.java │ │ │ ├── GrpcChannelConfigurer.java │ │ │ ├── GrpcChannelFactory.java │ │ │ ├── InProcessChannelFactory.java │ │ │ ├── InProcessOrAlternativeChannelFactory.java │ │ │ ├── NettyChannelFactory.java │ │ │ ├── ShadedNettyChannelFactory.java │ │ │ └── package-info.java │ │ │ ├── config │ │ │ ├── GrpcChannelProperties.java │ │ │ ├── GrpcChannelsProperties.java │ │ │ ├── NegotiationType.java │ │ │ └── package-info.java │ │ │ ├── inject │ │ │ ├── GrpcClient.java │ │ │ ├── GrpcClientBean.java │ │ │ ├── GrpcClientBeanPostProcessor.java │ │ │ ├── GrpcClientBeans.java │ │ │ ├── GrpcClientConstructorInjection.java │ │ │ ├── GrpcClientConstructorInjectionBeanFactoryPostProcessor.java │ │ │ ├── StubTransformer.java │ │ │ └── package-info.java │ │ │ ├── interceptor │ │ │ ├── AnnotationGlobalClientInterceptorConfigurer.java │ │ │ ├── DefaultRequestTimeoutSetupClientInterceptor.java │ │ │ ├── GlobalClientInterceptorConfigurer.java │ │ │ ├── GlobalClientInterceptorRegistry.java │ │ │ ├── GrpcGlobalClientInterceptor.java │ │ │ ├── OrderedClientInterceptor.java │ │ │ └── package-info.java │ │ │ ├── metrics │ │ │ ├── MetricsClientInstruments.java │ │ │ ├── MetricsClientInterceptor.java │ │ │ ├── MetricsClientMeters.java │ │ │ ├── MetricsClientStreamTracers.java │ │ │ └── package-info.java │ │ │ ├── nameresolver │ │ │ ├── DiscoveryClientNameResolver.java │ │ │ ├── DiscoveryClientResolverFactory.java │ │ │ ├── NameResolverRegistration.java │ │ │ ├── StaticNameResolver.java │ │ │ ├── StaticNameResolverProvider.java │ │ │ └── package-info.java │ │ │ ├── security │ │ │ ├── CallCredentialsHelper.java │ │ │ └── package-info.java │ │ │ └── stubfactory │ │ │ ├── AsyncStubFactory.java │ │ │ ├── BlockingStubFactory.java │ │ │ ├── FallbackStubFactory.java │ │ │ ├── FutureStubFactory.java │ │ │ ├── StandardJavaGrpcStubFactory.java │ │ │ └── StubFactory.java │ └── resources │ │ └── META-INF │ │ ├── additional-spring-configuration-metadata.json │ │ ├── services │ │ └── io.grpc.NameResolverProvider │ │ └── spring │ │ └── org.springframework.boot.autoconfigure.AutoConfiguration.imports │ └── test │ └── java │ └── net │ └── devh │ └── boot │ └── grpc │ └── client │ ├── channelfactory │ └── InProcessChannelFactoryTest.java │ ├── config │ ├── GrpcChannelPropertiesConfig.java │ ├── GrpcChannelPropertiesGivenUnitTest.java │ ├── GrpcChannelPropertiesGlobalTest.java │ ├── GrpcChannelPropertiesNegativeGivenUnitTest.java │ ├── GrpcChannelPropertiesNegativeNoUnitTest.java │ └── GrpcChannelPropertiesNoUnitTest.java │ ├── inject │ └── GrpcClientBeanPostProcessorTest.java │ ├── metrics │ ├── FakeClock.java │ ├── MetricsClientInterceptorTest.java │ └── MetricsClientStreamTracersTest.java │ └── nameresolver │ ├── DiscoveryClientNameResolverTest.java │ └── TestableListener.java ├── grpc-common-spring-boot ├── build.gradle └── src │ └── main │ ├── java │ └── net │ │ └── devh │ │ └── boot │ │ └── grpc │ │ └── common │ │ ├── autoconfigure │ │ ├── GrpcCommonCodecAutoConfiguration.java │ │ └── package-info.java │ │ ├── codec │ │ ├── AnnotationGrpcCodecDiscoverer.java │ │ ├── CodecType.java │ │ ├── GrpcCodec.java │ │ ├── GrpcCodecDefinition.java │ │ ├── GrpcCodecDiscoverer.java │ │ └── package-info.java │ │ ├── security │ │ ├── KeyStoreUtils.java │ │ ├── SecurityConstants.java │ │ └── package-info.java │ │ └── util │ │ ├── Constants.java │ │ ├── GrpcUtils.java │ │ ├── InterceptorOrder.java │ │ ├── SocketUtils.java │ │ └── package-info.java │ └── resources │ └── META-INF │ └── spring │ └── org.springframework.boot.autoconfigure.AutoConfiguration.imports ├── grpc-server-spring-boot-starter ├── build.gradle └── src │ ├── main │ ├── java │ │ └── net │ │ │ └── devh │ │ │ └── boot │ │ │ └── grpc │ │ │ └── server │ │ │ ├── advice │ │ │ ├── GrpcAdvice.java │ │ │ ├── GrpcAdviceDiscoverer.java │ │ │ ├── GrpcAdviceExceptionHandler.java │ │ │ ├── GrpcAdviceIsPresentCondition.java │ │ │ ├── GrpcExceptionHandler.java │ │ │ └── GrpcExceptionHandlerMethodResolver.java │ │ │ ├── autoconfigure │ │ │ ├── GrpcAdviceAutoConfiguration.java │ │ │ ├── GrpcHealthServiceAutoConfiguration.java │ │ │ ├── GrpcMetadataConsulConfiguration.java │ │ │ ├── GrpcMetadataEurekaConfiguration.java │ │ │ ├── GrpcMetadataNacosConfiguration.java │ │ │ ├── GrpcMetadataZookeeperConfiguration.java │ │ │ ├── GrpcReflectionServiceAutoConfiguration.java │ │ │ ├── GrpcServerAutoConfiguration.java │ │ │ ├── GrpcServerFactoryAutoConfiguration.java │ │ │ ├── GrpcServerMetricAutoConfiguration.java │ │ │ ├── GrpcServerMicrometerTraceAutoConfiguration.java │ │ │ ├── GrpcServerSecurityAutoConfiguration.java │ │ │ └── package-info.java │ │ │ ├── condition │ │ │ └── ConditionalOnInterprocessServer.java │ │ │ ├── config │ │ │ ├── ClientAuth.java │ │ │ ├── GrpcServerProperties.java │ │ │ ├── HealthOptions.java │ │ │ ├── HealthType.java │ │ │ └── package-info.java │ │ │ ├── error │ │ │ ├── GrpcExceptionInterceptor.java │ │ │ ├── GrpcExceptionListener.java │ │ │ ├── GrpcExceptionResponseHandler.java │ │ │ └── GrpcExceptionServerCall.java │ │ │ ├── event │ │ │ ├── GrpcServerLifecycleEvent.java │ │ │ ├── GrpcServerShutdownEvent.java │ │ │ ├── GrpcServerStartedEvent.java │ │ │ ├── GrpcServerTerminatedEvent.java │ │ │ └── package-info.java │ │ │ ├── health │ │ │ └── ActuatorGrpcHealth.java │ │ │ ├── interceptor │ │ │ ├── AnnotationGlobalServerInterceptorConfigurer.java │ │ │ ├── GlobalServerInterceptorConfigurer.java │ │ │ ├── GlobalServerInterceptorRegistry.java │ │ │ ├── GrpcGlobalServerInterceptor.java │ │ │ ├── OrderedServerInterceptor.java │ │ │ └── package-info.java │ │ │ ├── metrics │ │ │ ├── MetricsServerInstruments.java │ │ │ ├── MetricsServerMeters.java │ │ │ └── MetricsServerStreamTracers.java │ │ │ ├── nameresolver │ │ │ ├── SelfNameResolver.java │ │ │ ├── SelfNameResolverFactory.java │ │ │ └── package-info.java │ │ │ ├── scope │ │ │ └── GrpcRequestScope.java │ │ │ ├── security │ │ │ ├── authentication │ │ │ │ ├── AnonymousAuthenticationReader.java │ │ │ │ ├── BasicGrpcAuthenticationReader.java │ │ │ │ ├── BearerAuthenticationReader.java │ │ │ │ ├── CompositeGrpcAuthenticationReader.java │ │ │ │ ├── GrpcAuthenticationReader.java │ │ │ │ ├── SSLContextGrpcAuthenticationReader.java │ │ │ │ ├── X509CertificateAuthentication.java │ │ │ │ ├── X509CertificateAuthenticationProvider.java │ │ │ │ └── package-info.java │ │ │ ├── check │ │ │ │ ├── AbstractGrpcSecurityMetadataSource.java │ │ │ │ ├── AccessPredicate.java │ │ │ │ ├── AccessPredicateConfigAttribute.java │ │ │ │ ├── AccessPredicateVoter.java │ │ │ │ ├── AccessPredicates.java │ │ │ │ ├── GrpcSecurityMetadataSource.java │ │ │ │ ├── ManualGrpcSecurityMetadataSource.java │ │ │ │ └── package-info.java │ │ │ ├── interceptors │ │ │ │ ├── AbstractAuthenticatingServerCallListener.java │ │ │ │ ├── AuthenticatingServerInterceptor.java │ │ │ │ ├── AuthorizationCheckingServerInterceptor.java │ │ │ │ ├── DefaultAuthenticatingServerInterceptor.java │ │ │ │ ├── ExceptionTranslatingServerInterceptor.java │ │ │ │ └── package-info.java │ │ │ └── package-info.java │ │ │ ├── serverfactory │ │ │ ├── AbstractGrpcServerFactory.java │ │ │ ├── GrpcServerConfigurer.java │ │ │ ├── GrpcServerFactory.java │ │ │ ├── GrpcServerLifecycle.java │ │ │ ├── InProcessGrpcServerFactory.java │ │ │ ├── NettyGrpcServerFactory.java │ │ │ ├── ShadedNettyGrpcServerFactory.java │ │ │ └── package-info.java │ │ │ └── service │ │ │ ├── AnnotationGrpcServiceDiscoverer.java │ │ │ ├── GrpcService.java │ │ │ ├── GrpcServiceDefinition.java │ │ │ ├── GrpcServiceDiscoverer.java │ │ │ └── package-info.java │ └── resources │ │ └── META-INF │ │ └── spring │ │ └── org.springframework.boot.autoconfigure.AutoConfiguration.imports │ └── test │ ├── java │ └── net │ │ └── devh │ │ └── boot │ │ └── grpc │ │ └── server │ │ ├── advice │ │ └── GrpcAdviceDiscovererTest.java │ │ ├── autoconfigure │ │ ├── AwaitableStreamObserver.java │ │ ├── GrpcHealthServiceDefaultAutoConfigurationTest.java │ │ ├── GrpcHealthServiceFalseAutoConfigurationTest.java │ │ ├── GrpcHealthServiceTrueActuatorConfigurationTest.java │ │ ├── GrpcHealthServiceTrueAutoConfigurationTest.java │ │ ├── GrpcReflectionServiceDefaultAutoConfigurationTest.java │ │ ├── GrpcReflectionServiceFalseAutoConfigurationTest.java │ │ └── GrpcReflectionServiceTrueAutoConfigurationTest.java │ │ ├── config │ │ ├── GrpcServerPropertiesConfig.java │ │ ├── GrpcServerPropertiesGivenUnitTest.java │ │ ├── GrpcServerPropertiesNegativeGivenUnitTest.java │ │ ├── GrpcServerPropertiesNegativeNoUnitTest.java │ │ └── GrpcServerPropertiesNoUnitTest.java │ │ ├── health │ │ └── ActuatorGrpcHealthTest.java │ │ ├── metrics │ │ ├── FakeClock.java │ │ └── MetricsServerStreamTracersTest.java │ │ └── serverfactory │ │ ├── AbstractGrpcServerFactoryTest.java │ │ └── GrpcServerLifecycleTest.java │ └── resources │ └── logback-test.xml ├── private.key.enc ├── settings.gradle ├── testExamples.sh └── tests ├── build.gradle └── src └── test ├── java └── net │ └── devh │ └── boot │ └── grpc │ └── test │ ├── advice │ ├── AbstractSimpleServerClientTest.java │ ├── AdviceExceptionHandlingTest.java │ ├── AdviceIsPresentAutoConfigurationTest.java │ ├── AdviceNotPresentAutoConfigurationTest.java │ └── GrpcMetaDataUtils.java │ ├── codec │ ├── AbstractCodecTest.java │ ├── BeanCodecTest.java │ ├── CustomCodecTest.java │ ├── GzipCodecTest.java │ └── IdentityCodecTest.java │ ├── config │ ├── AnnotatedSecurityConfiguration.java │ ├── AwaitableServerClientCallConfiguration.java │ ├── BaseAutoConfiguration.java │ ├── BeanAnnotatedServiceConfig.java │ ├── DualInProcessConfiguration.java │ ├── GrpcAdviceConfig.java │ ├── InProcessConfiguration.java │ ├── ManualSecurityConfiguration.java │ ├── MetricConfiguration.java │ ├── OrderedClientInterceptorConfiguration.java │ ├── OrderedServerInterceptorConfiguration.java │ ├── ScopedServiceConfiguration.java │ ├── ServiceConfiguration.java │ ├── WithBasicAuthSecurityConfiguration.java │ └── WithCertificateSecurityConfiguration.java │ ├── inject │ ├── CustomGrpc.java │ ├── CustomStub.java │ ├── GrpcClientBeanInjectionNegativeTest.java │ ├── GrpcClientBeanInjectionTest.java │ ├── GrpcClientConstructorInjectionTest.java │ ├── GrpcClientFactoryMethodInjectionTest.java │ ├── GrpcClientInjectionTest.java │ ├── GrpcClientMetaAnnotationTest.java │ ├── OtherStub.java │ └── metaannotation │ │ └── GrpcClientWrapper.java │ ├── interceptor │ ├── DefaultClientInterceptorTest.java │ ├── DefaultServerInterceptorTest.java │ ├── OrderedClientInterceptorTest.java │ ├── OrderedServerInterceptorTest.java │ ├── PickupClientInterceptorTest.java │ └── PickupServerInterceptorTest.java │ ├── scope │ └── GrpcRequestScopeTest.java │ ├── security │ ├── AbstractSecurityTest.java │ ├── AbstractSecurityWithBasicAuthTest.java │ ├── AnnotatedSecurityWithBasicAuthTest.java │ ├── AnnotatedSecurityWithCertificateTest.java │ ├── ConcurrentSecurityTest.java │ ├── ManualSecurityWithBasicAuthTest.java │ └── ManualSecurityWithCertificateTest.java │ ├── server │ ├── ScopedTestServiceImpl.java │ ├── TestServiceImpl.java │ └── WaitingTestService.java │ ├── setup │ ├── AbstractBrokenServerClientTest.java │ ├── AbstractSimpleServerClientTest.java │ ├── BeanAnnotatedServiceTest.java │ ├── BrokenClientSelfSignedMutualSetupTest.java │ ├── BrokenServerSelfSignedMutualSetupTest.java │ ├── CustomCiphersAndProtocolsSetupTest.java │ ├── DefaultRequestTimeoutSetupTests.java │ ├── ImmediateConnectTests.java │ ├── InProcessDefaultSchemeConnectionTest.java │ ├── InProcessDefaultSchemeSelfAddressConnectionTest.java │ ├── InProcessSetupTest.java │ ├── InterAndInProcessSetup2Test.java │ ├── InterAndInProcessSetupTest.java │ ├── NameResolverConnectionTest.java │ ├── NameResolverIPv4ConnectionTest.java │ ├── NameResolverIPv6ConnectionTest.java │ ├── OnlyInProcessServerTest.java │ ├── PlaintextSetupTest.java │ ├── SelfDefaultSchemeConnectionTest.java │ ├── SelfNameResolverConnectionTest.java │ ├── SelfSignedInProcessSetupTest.java │ ├── SelfSignedMutualJksKeystoreSetupTest.java │ ├── SelfSignedMutualP12KeystoreSetupTest.java │ ├── SelfSignedMutualSetupTest.java │ ├── SelfSignedServerKeystoreSetupTest.java │ ├── SelfSignedServerSetupTest.java │ └── UnixSetupTest.java │ ├── shutdown │ ├── GrpcChannelLifecycleWithCallsTest.java │ └── GrpcServerLifecycleWithCallsTest.java │ └── util │ ├── AwaitableStreamObserver.java │ ├── DynamicTestCollection.java │ ├── EnableOnIPv6.java │ ├── FutureAssertions.java │ ├── GrpcAssertions.java │ ├── LoggerTestUtil.java │ ├── RequireIPv6Condition.java │ └── TriConsumer.java ├── kotlin └── net │ └── devh │ └── boot │ └── grpc │ └── test │ └── kotlin │ └── inject │ ├── ConstructorInjectionAnotherTestContainer.kt │ ├── ConstructorInjectionTestContainer.kt │ ├── GrpcClientBeanCustomConfig.kt │ ├── GrpcClientBeanTestConfig.kt │ ├── InjectionTestContainer.kt │ ├── KotlinGrpcClientBeanConstructorInjectionTest.kt │ ├── KotlinGrpcClientBeanInjectionTest.kt │ └── KotlinGrpcClientConstructorInjectionTest.kt ├── proto └── TestService.proto └── resources ├── certificates ├── client1.crt ├── client1.jks ├── client1.key ├── client1.p12 ├── client2.crt ├── client2.jks ├── client2.key ├── client2.p12 ├── generateCertificates.sh ├── server.crt ├── server.jks ├── server.key ├── server.p12 ├── trusted-clients-collection ├── trusted-clients.jks ├── trusted-clients.p12 ├── trusted-servers-collection ├── trusted-servers.jks └── trusted-servers.p12 └── logback-test.xml /.gitattributes: -------------------------------------------------------------------------------- 1 | # Handle line endings automatically for files detected as text 2 | # and leave all files detected as binary untouched. 3 | * text=auto 4 | 5 | # 6 | # The above will handle all files NOT found below 7 | # 8 | # These files are text and should be normalized (Convert crlf => lf) 9 | *.bash text eol=lf 10 | *.bat text eol=crlf 11 | *.df text 12 | *.java text diff=java 13 | *.js text 14 | *.json text 15 | *.properties text 16 | # ensure that sh files can be run using git-bash or wsl even if pulled on Windows from the repo 17 | *.sh text eol=lf 18 | *.txt text 19 | *.xml text 20 | *.yml text 21 | *.yaml text 22 | *.md text 23 | 24 | # These files are binary and should be left untouched 25 | # (binary is a macro for -text -diff) 26 | *.gz binary 27 | *.class binary 28 | *.dll binary 29 | *.ear binary 30 | *.gif binary 31 | *.ico binary 32 | *.jar binary 33 | *.jpg binary 34 | *.jpeg binary 35 | *.png binary 36 | *.so binary 37 | *.war binary 38 | *.p12 binary 39 | *.zip binary 40 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | title: '' 5 | labels: bug 6 | assignees: '' 7 | 8 | --- 9 | 10 | **The context** 11 | 12 | What do you wish to achieve? 13 | 14 | **The bug** 15 | 16 | What's the problem? What's not working? What do you expect to happen. 17 | 18 | **Stacktrace and logs** 19 | 20 | Is there a stacktrace or a hint in the logs? (very important) 21 | Screenshots work as well, but don't screenshot your logs. 22 | 23 | **Steps to Reproduce** 24 | 25 | Steps to reproduce the behavior: 26 | 1. Go to '...' 27 | 2. Click on '....' 28 | 3. Scroll down to '....' 29 | 4. See error 30 | 31 | **The application's environment** 32 | 33 | Which versions do you use? 34 | * Spring (boot): 35 | * grpc-java: 36 | * grpc-spring-boot-starter: 37 | * java: version + architecture (64bit?) 38 | * Other relevant libraries... 39 | 40 | **Additional context** 41 | 42 | * Did it ever work before? 43 | * Do you have a demo? 44 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | title: '' 5 | labels: enhancement 6 | assignees: '' 7 | 8 | --- 9 | 10 | **The problem** 11 | 12 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] 13 | 14 | **The solution** 15 | 16 | A clear and concise description of what you want to happen. 17 | 18 | **Alternatives considered** 19 | 20 | A clear and concise description of any alternative solutions or features you've considered. 21 | 22 | **Additional context** 23 | 24 | Add any other context or screenshots about the feature request here. 25 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/question.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Question 3 | about: Ask a question about this library and its usage 4 | title: '' 5 | labels: question 6 | assignees: '' 7 | 8 | --- 9 | 10 | **The context** 11 | 12 | What do you wish to achieve? 13 | 14 | **The question** 15 | 16 | What's the problem? What's not working? What's missing and why do you need it? 17 | 18 | **Stacktraces and logs** 19 | 20 | Do you have any relevant stacktraces or logs of your attempts? 21 | 22 | **The application's environment** 23 | 24 | Which versions do you use? 25 | * Spring (boot): 26 | * grpc-java: 27 | * grpc-spring-boot-starter: 28 | * java: version + architecture (64bit?) 29 | * Other relevant libraries... 30 | 31 | **Additional information** 32 | 33 | * Did it ever work before? 34 | * How can we reproduce it? 35 | * Do you have a demo? 36 | -------------------------------------------------------------------------------- /.github/renovate.json5: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://docs.renovatebot.com/renovate-schema.json", 3 | "extends": ["config:base"], 4 | "labels": ["dependencies"], 5 | "ignoreDeps": ["HH:mm"] 6 | } 7 | -------------------------------------------------------------------------------- /.github/workflows/build-master.yml: -------------------------------------------------------------------------------- 1 | name: Build master branch 2 | 3 | on: 4 | push: 5 | branches: 6 | - master 7 | 8 | jobs: 9 | build: 10 | name: Build on java ${{ matrix.java }} 11 | runs-on: ubuntu-latest 12 | strategy: 13 | matrix: 14 | java: ['17', '21'] 15 | steps: 16 | - name: Checkout code 17 | uses: actions/checkout@v4 18 | 19 | - name: Validate Gradle wrapper 20 | uses: gradle/wrapper-validation-action@v3 21 | 22 | - name: Set up java ${{ matrix.java }} 23 | uses: actions/setup-java@v4 24 | with: 25 | distribution: 'temurin' 26 | java-version: ${{ matrix.java }} 27 | check-latest: true 28 | 29 | - name: Decrypt file 30 | run: openssl aes-256-cbc -K ${{ secrets.ENCRYPTED_KEY }} -iv ${{ secrets.ENCRYPTED_IV }} -in private.key.enc -out ./private.key -d && gpg --batch --import ./private.key || echo 31 | 32 | - name: Build with Gradle 33 | uses: gradle/actions/setup-gradle@v3 34 | with: 35 | arguments: --scan --stacktrace --warning-mode=all build 36 | 37 | - name: Deploy with Gradle 38 | if: ${{ matrix.java == '17' }} 39 | uses: gradle/actions/setup-gradle@v3 40 | with: 41 | arguments: --scan publish -x check -Psigning.gnupg.executable=gpg -Psigning.gnupg.keyName=${{ secrets.GPG_NAME }} -Psigning.gnupg.passphrase=${{ secrets.GPG_PASSWORD }} 42 | env: 43 | OSSRH_USER: ${{ secrets.OSSRH_USER }} 44 | OSSRH_PASS: ${{ secrets.OSSRH_PASS }} 45 | -------------------------------------------------------------------------------- /.github/workflows/pull-request.yml: -------------------------------------------------------------------------------- 1 | name: Pull Request CI 2 | 3 | on: ['pull_request'] 4 | 5 | jobs: 6 | build: 7 | name: Build on java ${{ matrix.java }} 8 | runs-on: ubuntu-latest 9 | strategy: 10 | matrix: 11 | java: ['17', '21'] 12 | steps: 13 | - name: Checkout code 14 | uses: actions/checkout@v4 15 | 16 | - name: Validate Gradle wrapper 17 | uses: gradle/wrapper-validation-action@v3 18 | 19 | - name: Set up java ${{ matrix.java }} 20 | uses: actions/setup-java@v4 21 | with: 22 | distribution: temurin 23 | java-version: ${{ matrix.java }} 24 | check-latest: true 25 | 26 | - name: Build with Gradle 27 | uses: gradle/actions/setup-gradle@v3 28 | with: 29 | arguments: --scan --stacktrace --warning-mode=all build 30 | 31 | # Avoid publish errors when upgrading gradle version and dependencyManager plugin 32 | - name: Try publishToMavenLocal 33 | uses: gradle/actions/setup-gradle@v3 34 | with: 35 | arguments: publishToMavenLocal 36 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | build 2 | **/generated 3 | classes 4 | .gradle 5 | 6 | .DS_Store 7 | target/ 8 | !.mvn/wrapper/maven-wrapper.jar 9 | 10 | ### IntelliJ IDEA ### 11 | .idea 12 | *.iws 13 | *.iml 14 | *.ipr 15 | **/out 16 | 17 | ### Eclipse ### 18 | target/ 19 | bin/ 20 | .classpath 21 | .project 22 | .settings/ 23 | .factorypath 24 | .checkstyle 25 | 26 | ## VSCode 27 | .vscode/ 28 | .devcontainer/ -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # How to contribute 2 | 3 | We definitely welcome your patches and contributions to gRPC-Spring-Boot-Starter! 4 | 5 | If you are new to github, please start by reading [Pull Request howto](https://help.github.com/articles/about-pull-requests/) 6 | 7 | ## Code Formatting 8 | 9 | Code formatting is enforced using the [Spotless](https://github.com/diffplug/spotless) Gradle plugin. 10 | You can use `gradle spotlessJavaApply` (java only) or `gradle spotlessApply` (all files) 11 | to format new code. Please run this task before submitting your pull request. 12 | 13 | ### Eclipse 14 | 15 | For the eclipse IDE we use the following formatter files: 16 | 17 | * [extra/eclipse-formatter.xml](extra/eclipse/eclipse-formatter.xml) 18 | * [extra/eclipse.importorder](extra/eclipse/eclipse.importorder) 19 | 20 | These will help you maintaing the files order, if you run the formatter from eclipse. 21 | There are slight differences to the `spotless` plugin so please run it before submitting your PR anyway. 22 | 23 | ### IntelliJ IDEA 24 | 25 | For IntelliJ IDEA there's a [Eclipse Code Formatter plugin](https://plugins.jetbrains.com/plugin/6546) you can use in 26 | conjunction with the Eclipse setting files. 27 | -------------------------------------------------------------------------------- /crowdin.yml: -------------------------------------------------------------------------------- 1 | files: 2 | - source: /docs/en/client 3 | translation: /docs/%locale%/client/%original_file_name% 4 | - source: /README.md 5 | translation: /README-%locale%.md 6 | - source: /docs/en/server 7 | translation: /docs/%locale%/server/%original_file_name% 8 | - source: /docs/en/*.md 9 | translation: /docs/%locale%/%original_file_name% 10 | -------------------------------------------------------------------------------- /docs/_config.yml: -------------------------------------------------------------------------------- 1 | theme: jekyll-theme-cayman 2 | -------------------------------------------------------------------------------- /docs/assets/css/style.scss: -------------------------------------------------------------------------------- 1 | --- 2 | --- 3 | 4 | @import "{{ site.theme }}"; 5 | 6 | @media screen and (min-width: 64em) { 7 | .page-header { 8 | padding:3rem 3rem; 9 | } 10 | } 11 | @media screen and (min-width: 42em) and (max-width: 64em) { 12 | .page-header { 13 | padding:2rem 3rem; 14 | } 15 | } 16 | @media screen and (max-width: 42em) { 17 | .page-header { 18 | padding:2rem 1rem 19 | } 20 | } -------------------------------------------------------------------------------- /docs/en/benchmarking.md: -------------------------------------------------------------------------------- 1 | # Benchmarking 2 | 3 | [<- Back to Index](index.md) 4 | 5 | This library does not add any performance overhead to gRPC-java. 6 | 7 | Please refer to the official gRPC benchmarks: 8 | 9 | - [grpc.io: Benchmarking](https://grpc.io/docs/guides/benchmarking/) 10 | - [grpc-java: Running Benchmarks](https://github.com/grpc/grpc-java/tree/master/benchmarks#grpc-benchmarks) 11 | 12 | gRPC offers various benefits over plain HTTP, but it's hard to put it in actual numbers. 13 | Heavily optimized web-servers perform as good as normal gRPC-servers. 14 | 15 | Here are the main benefits/differences from grpc over plain HTTP: 16 | 17 | - Binary data format (a lot faster, but not human readable) 18 | - Protobuf defined data scheme, that can be used to generate data classes and clients for many languages 19 | - HTTP/2 connections and connection pooling 20 | 21 | ---------- 22 | 23 | [<- Back to Index](index.md) 24 | -------------------------------------------------------------------------------- /docs/en/contributions.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | [<- Back to Index](index.md) 4 | 5 | Contributions are always welcome. 6 | 7 | For more information refer to our [contribution guidelines](https://github.com/grpc-ecosystem/grpc-spring/blob/master/CONTRIBUTING.md). 8 | 9 | **Thanks to all our [contributors](https://github.com/grpc-ecosystem/grpc-spring/graphs/contributors)!** 10 | 11 | ---------- 12 | 13 | [<- Back to Index](index.md) 14 | -------------------------------------------------------------------------------- /docs/en/examples.md: -------------------------------------------------------------------------------- 1 | # Examples 2 | 3 | The example projects demonstrate how to use the projects. 4 | 5 | These projects work as is and could be used as templates for your own projects. 6 | We use them to verify that this library works in different environments, and we don't break anything unnoticed. 7 | 8 | > **Note:** If you have questions regarding these sample projects or would like an example for another use case, 9 | > feel free to open an [issue](https://github.com/grpc-ecosystem/grpc-spring/issues). 10 | 11 | ## Local example 12 | 13 | The simplest setup of all, using a local server and one or more clients. 14 | 15 | - [Server](https://github.com/grpc-ecosystem/grpc-spring/tree/master/examples/local-grpc-server) 16 | - [Client](https://github.com/grpc-ecosystem/grpc-spring/tree/master/examples/local-grpc-client) 17 | - [Instructions](https://github.com/grpc-ecosystem/grpc-spring/tree/master/examples#local-mode) 18 | 19 | ## Cloud example 20 | 21 | A setup for cloud environments using a eureka service discovery service. 22 | 23 | - [Eureka-Server](https://github.com/grpc-ecosystem/grpc-spring/tree/master/examples/cloud-eureka-server) 24 | - [Server](https://github.com/grpc-ecosystem/grpc-spring/tree/master/examples/cloud-grpc-server) 25 | - [Client](https://github.com/grpc-ecosystem/grpc-spring/tree/master/examples/cloud-grpc-client) 26 | - [Instructions](https://github.com/grpc-ecosystem/grpc-spring/tree/master/examples#cloud-mode) 27 | 28 | ## Basic Auth Example 29 | 30 | A setup that demonstrates the usage of spring-security with grpc. 31 | This setup uses basic auth for simplicity reasons, but other authentication mechanism can be used for this as well. 32 | 33 | - [Server](https://github.com/grpc-ecosystem/grpc-spring/tree/master/examples/security-grpc-server) 34 | - [Client](https://github.com/grpc-ecosystem/grpc-spring/tree/master/examples/security-grpc-client) 35 | - [Instructions](https://github.com/grpc-ecosystem/grpc-spring/tree/master/examples#with-basic-auth-security) 36 | -------------------------------------------------------------------------------- /docs/en/flavors.md: -------------------------------------------------------------------------------- 1 | # gRPC-Java Flavors 2 | 3 | Aside from [grpc-java](https://github.com/grpc/grpc-java/), this library also supports other java based 4 | grpc-implementations. 5 | 6 | | Flavor | Server | Client | 7 | | --- | --- | --- | 8 | | [grpc-java](https://github.com/grpc/grpc-java/) | ✔️ | ✔️ | 9 | | [Reactive gRPC (Reactor)](https://github.com/salesforce/reactive-grpc/tree/master/reactor) | ✔️ | ✏️ | 10 | | [Reactive gRPC (RxJava)](https://github.com/salesforce/reactive-grpc/tree/master/rx-java) | ✔️ | ✏️ | 11 | | [grpc-kotlin](https://github.com/grpc/grpc-kotlin) | ✔️ | ✏️ | 12 | | [ScalaPB](https://scalapb.github.io/grpc.html) | ✔️ | ✏️ | 13 | | [akka-grpc](https://github.com/akka/akka-grpc) | ✔️ | ✏️ | 14 | | ... | ✔️ | ✏️ | 15 | 16 | *✔️ = Build-in support* | 17 | *✏️ = Requires customization* 18 | 19 | > **Note:** You might require additional dependencies depending on your grpc java flavor. 20 | 21 | ## Server side 22 | 23 | The server side should work without any additional configuration. Just annotatate your implementation of the generated 24 | `BindableService` class with `@GrpcService` and it will be picked up automatically. 25 | 26 | See also: 27 | 28 | - [Server - Getting Started](server/getting-started.md) 29 | 30 | ## Client side 31 | 32 | The client side requires a `StubFactory` for each type of stub. 33 | 34 | This library ships the following stub factory beans by default: 35 | 36 | - gRPC-Java 37 | - `AbstractAsyncStub` -> `AsyncStubFactory` 38 | - `AbstractBlockingStub` -> `BlockingStubFactory` 39 | - `AbstractFutureStub` -> `FutureStubFactory` 40 | 41 | Please report missing stub types so that we can add support for them. 42 | 43 | See also: 44 | 45 | - [Client - Getting Started](client/getting-started.md) 46 | - [Client - Configuration - StubFactory](client/configuration.md#stubfactory) 47 | -------------------------------------------------------------------------------- /docs/en/index.md: -------------------------------------------------------------------------------- 1 | # gRPC-Spring-Boot-Starter Documentation 2 | 3 | gRPC-spring-boot-starter combines [google's open-source high performance RPC-framework](https://grpc.io) with 4 | [spring boot's ease of setup](https://spring.io/projects/spring-boot). 5 | This project simplifies the gRPC-server/client setup to adding one dependency to your project and adding a single 6 | annotation to your service class / client (stub) field. 7 | The features of this library are meant to complement your experience with gRPC and still allow you to do any 8 | customization you need for your project. 9 | 10 | ## Table of Contents 11 | 12 | - Server 13 | - [Getting Started](server/getting-started.md) 14 | - [Configuration](server/configuration.md) 15 | - [Exception Handling](server/exception-handling.md) 16 | - [Contextual Data / Scoped Beans](server/contextual-data.md) 17 | - [Testing the Service](server/testing.md) 18 | - [Server Events](server/events.md) 19 | - [Security](server/security.md) 20 | - Client 21 | - [Getting Started](client/getting-started.md) 22 | - [Configuration](client/configuration.md) 23 | - [Security](client/security.md) 24 | - [Tests with Grpc-Stubs](client/testing.md) 25 | - Others setups 26 | - [Trouble-Shooting](trouble-shooting.md) 27 | - [Example Projects](examples.md) 28 | - [gRPC-Java Flavors](flavors.md) 29 | - [Version Overview](versions.md) 30 | - [Spring Boot Actuator / Metrics Support](actuator.md) 31 | - [Brave-Tracing / Spring Cloud Sleuth Support](brave.md) 32 | - [Kubernetes Setup](kubernetes.md) 33 | - [Benchmarking](benchmarking.md) 34 | - [Contributing](contributions.md) 35 | -------------------------------------------------------------------------------- /docs/index.md: -------------------------------------------------------------------------------- 1 | # gRPC-Spring-Boot-Starter Documentation 2 | 3 | Please select a language: 4 | 5 | - [English](en) 6 | - [中文](zh-CN) 7 | -------------------------------------------------------------------------------- /docs/zh-CN/benchmarking.md: -------------------------------------------------------------------------------- 1 | # 基准测试 2 | 3 | [<- 返回索引](index.md) 4 | 5 | 这个项目不会给 gRPC-java 增加任何性能开销。 6 | 7 | 请参考官方的 gRPC 基准测试: 8 | 9 | - [grpc.io: Benchmarking](https://grpc.io/docs/guides/benchmarking/) 10 | - [grpc-java: Running Benchmarks](https://github.com/grpc/grpc-java/tree/master/benchmarks#grpc-benchmarks) 11 | 12 | 与纯 HTTP 相比,gRPC 具有很多优势,但是很难将它数字化。 经过高度优化的 Web 服务器的性能与普通的 gRPC 服务器可能一样好。 13 | 14 | 下面是普通HTTP与 grpc 的主要优点/差异: 15 | 16 | - 二进制数据格式 (更快, 但不可读) 17 | - Protobuf 定义的数据结构,可以用于为许多语言生成数据类和客户端。 18 | - HTTP/2 连接和连接池 19 | 20 | ---------- 21 | 22 | [<- 返回索引](index.md) 23 | -------------------------------------------------------------------------------- /docs/zh-CN/contributions.md: -------------------------------------------------------------------------------- 1 | # 参与贡献 2 | 3 | [<- 返回索引](index.md) 4 | 5 | 我们始终欢迎您对项目作出任何贡献。 6 | 7 | 详情请参阅我们的[贡献准则](https://github.com/grpc-ecosystem/grpc-spring/blob/master/CONTRIBUTING.md)。 8 | 9 | **感谢我们所有的[贡献者](https://github.com/grpc-ecosystem/grpc-spring/graphs/contributors)!** 10 | 11 | ---------- 12 | 13 | [<- 返回索引](index.md) 14 | -------------------------------------------------------------------------------- /docs/zh-CN/examples.md: -------------------------------------------------------------------------------- 1 | # 示例 2 | 3 | 示例项目演示如何使用这些项目。 4 | 5 | 这些项目可以作为您自己的项目的模板。 我们使用它们来验证这个库在不同的环境中运行,我们不会在不受注意的情况下改变它的行为。 6 | 7 | > **注意:** 如果您对这些项目有疑问,或者想要其他的示例,随时可以提出一个 [issue](https://github.com/grpc-ecosystem/grpc-spring/issues)。 8 | 9 | ## 本地示例 10 | 11 | 最简单的设置,使用本地服务端和一个或多个客户端 12 | 13 | - [服务端](https://github.com/grpc-ecosystem/grpc-spring/tree/master/examples/local-grpc-server) 14 | - [客户端](https://github.com/grpc-ecosystem/grpc-spring/tree/master/examples/local-grpc-client) 15 | - [说明](https://github.com/grpc-ecosystem/grpc-spring/tree/master/examples#local-mode) 16 | 17 | ## Cloud 示例 18 | 19 | 使用 eureka 服务发现的 Cloud 环境。 20 | 21 | - [Eureka 服务](https://github.com/grpc-ecosystem/grpc-spring/tree/master/examples/cloud-eureka-server) 22 | - [服务端](https://github.com/grpc-ecosystem/grpc-spring/tree/master/examples/cloud-grpc-server) 23 | - [客户端](https://github.com/grpc-ecosystem/grpc-spring/tree/master/examples/cloud-grpc-client) 24 | - [说明](https://github.com/grpc-ecosystem/grpc-spring/tree/master/examples#cloud-mode) 25 | 26 | ## 基础认证示例 27 | 28 | 演示了 grpc 跟 spring security 的设置。 为了简单起见,此设置使用 Basic 身份验证,但也可以为其使用其他身份验证机制。 29 | 30 | - [服务端](https://github.com/grpc-ecosystem/grpc-spring/tree/master/examples/security-grpc-server) 31 | - [客户端](https://github.com/grpc-ecosystem/grpc-spring/tree/master/examples/security-grpc-client) 32 | - [说明](https://github.com/grpc-ecosystem/grpc-spring/tree/master/examples#with-basic-auth-security) 33 | -------------------------------------------------------------------------------- /docs/zh-CN/flavors.md: -------------------------------------------------------------------------------- 1 | # gRPC-Java 类似风格的库 2 | 3 | 除了 [grpc-java](https://github.com/grpc/grpc-java/), 该库还支持其他基于 java 的 grpc 实现. 4 | 5 | | 库 | 服务端 | 客户端 | 6 | | ------------------------------------------------------------------------------------------ | --- | --- | 7 | | [grpc-java](https://github.com/grpc/grpc-java/) | ✔️ | ✔️ | 8 | | [Reactive gRPC (Reactor)](https://github.com/salesforce/reactive-grpc/tree/master/reactor) | ✔️ | ✏️ | 9 | | [Reactive gRPC (RxJava)](https://github.com/salesforce/reactive-grpc/tree/master/rx-java) | ✔️ | ✏️ | 10 | | [grpc-kotlin](https://github.com/grpc/grpc-kotlin) | ✔️ | ✏️ | 11 | | [ScalaPB](https://scalapb.github.io/grpc.html) | ✔️ | ✏️ | 12 | | [akka-grpc](https://github.com/akka/akka-grpc) | ✔️ | ✏️ | 13 | | ... | ✔️ | ✏️ | 14 | 15 | *✔️ = 内置支持* | *✏️ = 需要自定义* 16 | 17 | > **注意:** 您可能需要引入额外的依赖库,这取决于您所用的库。 18 | 19 | ## 服务端 20 | 21 | 服务器端应该在没有任何额外配置的情况下工作。 只需要在 `BindableService` 的实现类上增加 `@GrpcService` 注解。 22 | 23 | 参阅: 24 | 25 | - [服务端 - 入门](server/getting-started.md) 26 | 27 | ## 客户端 28 | 29 | 客户端对每种类型的 stub 都需要一个 `StubFactory` 。 30 | 31 | 该库默认提供以下几种 stub 的 工厂 bean: 32 | 33 | - gRPC-Java 34 | - `AbstractAsyncStub` -> `AsyncStubFactory` 35 | - `AbstractBlockingStub` -> `BlockingStubFactory` 36 | - `AbstractFutureStub` -> `FutureStubFactory` 37 | 38 | 请告知我们不支持的 stub 类型,我们可以添加对它们的支持. 39 | 40 | 参阅: 41 | 42 | - [客户端-入门](client/getting-started.md) 43 | - [客户端 - 配置 - StubFactory](client/configuration.md#stubfactory) 44 | -------------------------------------------------------------------------------- /docs/zh-CN/index.md: -------------------------------------------------------------------------------- 1 | # gRPC-Spring-Boot-Starter 文档 2 | 3 | gRPC-Spring-Boot-Starter 将 [Google的开源高性能RPC框架](https://grpc.io) 与 [Spring Boot 进行整合](https://spring.io/projects/spring-boot) 该项目简化了 gRPC 服务端 / 客户端的设置,只需要为项目添加了一个依赖项,并在服务实现类 / 客户 (stub) 字段上添加了一个的注解。 这个项目提供的特性仍然能复用您使用 gRPC 的经验,并且允许您执行任何自定义操作。 4 | 5 | ## 目录 6 | 7 | - 服务端 8 | - [入门指南](server/getting-started.md) 9 | - [配置](server/configuration.md) 10 | - [异常处理](server/exception-handling.md) 11 | - [上下文数据 / Bean 的作用域](server/contextual-data.md) 12 | - [测试服务](server/testing.md) 13 | - [服务端事件](server/events.md) 14 | - [安全性](server/security.md) 15 | - 客户端 16 | - [入门指南](client/getting-started.md) 17 | - [配置](client/configuration.md) 18 | - [安全性](client/security.md) 19 | - [使用 Grpc-Stubs 测试](client/testing.md) 20 | - 其他设置 21 | - [疑难解答](trouble-shooting.md) 22 | - [示例项目](examples.md) 23 | - [gRPC-Java 类似风格的库](flavors.md) 24 | - [版本概述](versions.md) 25 | - [支持 Spring Boot Actuator / Metrics](actuator.md) 26 | - [支持 Brave-Tracing / Spring Cloud Sleuth](brave.md) 27 | - [Kubernetes 设置](kubernetes.md) 28 | - [基准测试](benchmarking.md) 29 | - [参与贡献](contributions.md) 30 | -------------------------------------------------------------------------------- /docs/zh-CN/server/contextual-data.md: -------------------------------------------------------------------------------- 1 | # 上下文数据 / Bean 的作用域 2 | 3 | [<- 返回索引](../index.md) 4 | 5 | 本节描述您如何保存请求上下文数据 / 每个请求的数据。 6 | 7 | ## 目录 8 | 9 | - [警告语](#警告语) 10 | - [grpcRequest 作用域](#grpcRequest 作用域) 11 | 12 | ## 附加主题 13 | 14 | - [入门指南](getting-started.md) 15 | - [配置](configuration.md) 16 | - [异常处理](exception-handling.md) 17 | - *上下文数据 / Bean 的作用域* 18 | - [测试服务](testing.md) 19 | - [服务端事件](events.md) 20 | - [安全性](security.md) 21 | 22 | ## 警告语 23 | 24 | 在 grpc-java 中,消息发送 / 请求处理中的不同阶段可能在不同的线程中运行。 流式调用中也是这样。 避免在 `ServerIntercetor` 和 grpc 服务方法实现中(在整个 gRPC 上下文中)使用 `ThreadLocal`。 归根到底来说,每个单个信息都可能会在不同的线程中运行。 如果您想要在会话中存储数据,请使用 grpc 的 `Context` 或 `grpcRequest` 作用域。 25 | 26 | ## grpcRequest 作用域 27 | 28 | 该项目添加了一个`grpcRequest`,该功能类似于 Spring Web 的`request` 作用域。 它只适用于单个的请求。 29 | 30 | 首先需要用 `@Scope` 注解定义 Bean: 31 | 32 | ````java 33 | @Bean 34 | @Scope(scopeName = "grpcRequest", proxyMode = ScopedProxyMode.TARGET_CLASS) 35 | //@Scope(scopeName = GrpcRequestScope.GRPC_REQUEST_SCOPE_NAME, proxyMode = ScopedProxyMode.TARGET_CLASS) 36 | ScopedBean myScopedBean() { 37 | return new ScopedBean(); 38 | } 39 | ```` 40 | 41 | > `proxyMode = TARGET_CLASS` 是必须的,除非在另一个 `grpcRequest` 作用域中配置了它. 请注意,这个`proxyMode` 不适用于 final 修饰的类和方法。 42 | 43 | 之后,您就可以像以前那样使用 Bean: 44 | 45 | ````java 46 | @Autowired 47 | private ScopedBean myScopedBean; 48 | 49 | @Override 50 | public void grpcMethod(Request request, StreamObserver responseObserver) { 51 | responseObserver.onNext(myScopedBean.magic(request)); 52 | responseObserver.onCompleted(); 53 | } 54 | ```` 55 | 56 | ## 附加主题 57 | 58 | - [入门指南](getting-started.md) 59 | - [配置](configuration.md) 60 | - [异常处理](exception-handling.md) 61 | - *上下文数据 / Bean 的作用域* 62 | - [测试服务](testing.md) 63 | - [服务端事件](events.md) 64 | - [安全性](security.md) 65 | 66 | ---------- 67 | 68 | [<- 返回索引](../index.md) 69 | -------------------------------------------------------------------------------- /docs/zh-CN/server/events.md: -------------------------------------------------------------------------------- 1 | # 服务端事件 2 | 3 | [<- 返回索引](../index.md) 4 | 5 | 本节介绍如何订阅 grpc 服务端相关的事件。 6 | 7 | ## 目录 8 | 9 | - [事件概览](#事件概览) 10 | - [GrpcServerLifecycleEvent](#grpcServerLifecycleEvent) 11 | - [GrpcServerStartedEvent](#grpcServerStartedEvent) 12 | - [GrpcServerShutdownEvent](#grpcServerShutdownEvent) 13 | - [GrpcServerTerminatedEvent](#grpcServerTerminatedEvent) 14 | - [订阅事件](#订阅事件) 15 | 16 | ## 附加主题 17 | 18 | - [入门指南](getting-started.md) 19 | - [配置](configuration.md) 20 | - [异常处理](exception-handling.md) 21 | - [上下文数据 / Bean 的作用域](contextual-data.md) 22 | - [测试服务](testing.md) 23 | - *服务端事件* 24 | - [安全性](security.md) 25 | 26 | ## 事件概览 27 | 28 | ### GrpcServerLifecycleEvent 29 | 30 | 与`GrpcServerLifecycle`变化有关的所有事件的抽象基类。 31 | 32 | ### GrpcServerStartedEvent 33 | 34 | 此事件将在服务端启动后触发。 35 | 36 | ### GrpcServerShutdownEvent 37 | 38 | 此事件将在服务端关闭前触发。 服务端将不再处理新请求。 39 | 40 | ### GrpcServerTerminatedEvent 41 | 42 | 此事件将在服务端关闭后触发。 服务端将不再处理任何请求。 43 | 44 | ## 订阅事件 45 | 46 | 为了订阅这些事件,你只需在你任何 `@Component` 中的 public 方法上使用 `@EventListener` 注解。 47 | 48 | ````java 49 | @Component 50 | public class MyEventListenerComponent { 51 | 52 | @EventListener 53 | public void onServerStarted(GrpcServerStartedEvent event) { 54 | System.out.println("gRPC Server started, listening on address: " + event.getAddress() + ", port: " + event.getPort()); 55 | } 56 | 57 | } 58 | ```` 59 | 60 | ## 附加主题 61 | 62 | - [入门指南](getting-started.md) 63 | - [配置](configuration.md) 64 | - [异常处理](exception-handling.md) 65 | - [上下文数据 / Bean 的作用域](contextual-data.md) 66 | - [测试服务](testing.md) 67 | - *服务端事件* 68 | - [安全性](security.md) 69 | 70 | ---------- 71 | 72 | [<- 返回索引](../index.md) 73 | -------------------------------------------------------------------------------- /examples/cloud-eureka-server/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'org.springframework.boot' 3 | } 4 | 5 | dependencies { 6 | implementation 'org.springframework.cloud:spring-cloud-starter-netflix-eureka-server' 7 | implementation 'org.springframework.boot:spring-boot-starter-actuator' 8 | 9 | testImplementation('org.springframework.boot:spring-boot-starter-test') 10 | } 11 | -------------------------------------------------------------------------------- /examples/cloud-eureka-server/src/main/java/net/devh/boot/grpc/examples/cloud/server/EurekaServerApplication.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2023 The gRPC-Spring Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.devh.boot.grpc.examples.cloud.server; 18 | 19 | import org.springframework.boot.SpringApplication; 20 | import org.springframework.boot.autoconfigure.SpringBootApplication; 21 | import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer; 22 | 23 | /** 24 | * Eureka cloud discovery server application. 25 | */ 26 | @EnableEurekaServer 27 | @SpringBootApplication 28 | public class EurekaServerApplication { 29 | 30 | /** 31 | * Starts the Eureka cloud discovery server application. 32 | * 33 | * @param args The arguments to pass to the application. 34 | */ 35 | public static void main(final String... args) { 36 | SpringApplication.run(EurekaServerApplication.class, args); 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /examples/cloud-eureka-server/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8761 3 | 4 | spring: 5 | application: 6 | name: eureka-server 7 | 8 | eureka: 9 | instance: 10 | hostname: localhost 11 | prefer-ip-address: true 12 | status-page-url-path: /actuator/info 13 | health-check-url-path: /actuator/health 14 | lease-expiration-duration-in-seconds: 30 15 | lease-renewal-interval-in-seconds: 30 16 | client: 17 | registerWithEureka: false 18 | fetchRegistry: false 19 | serviceUrl: 20 | defaultZone: http://localhost:8761/eureka/ 21 | server: 22 | enable-self-preservation: false 23 | 24 | management: 25 | endpoint: 26 | shutdown: 27 | enabled: true 28 | -------------------------------------------------------------------------------- /examples/cloud-grpc-client/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'org.springframework.boot' 3 | } 4 | 5 | def discoveryProvider = project.findProperty('discovery') ?: 'consul'; 6 | 7 | dependencies { 8 | switch (discoveryProvider) { 9 | case "nacos": { 10 | implementation 'com.alibaba.cloud:spring-cloud-starter-alibaba-nacos-discovery' 11 | break; 12 | } 13 | case "consul": { 14 | implementation 'org.springframework.cloud:spring-cloud-starter-consul-discovery' 15 | break; 16 | } 17 | case "eureka": { 18 | implementation 'org.springframework.cloud:spring-cloud-starter-netflix-eureka-client' 19 | break; 20 | } 21 | case "zookeeper": { 22 | implementation 'org.springframework.cloud:spring-cloud-starter-zookeeper-discovery' 23 | break; 24 | } 25 | } 26 | 27 | implementation project(':grpc-client-spring-boot-starter') // Replace with actual dependency "net.devh:grpc-client-spring-boot-starter:${springBootGrpcVersion}" 28 | implementation project(':examples:grpc-lib') // Replace with your grpc interface spec 29 | 30 | // For demonstration only 31 | implementation 'org.springframework.boot:spring-boot-starter-actuator' 32 | implementation 'org.springframework.boot:spring-boot-starter-web' 33 | } 34 | 35 | bootRun { 36 | args = ["--spring.profiles.active=" + discoveryProvider] 37 | } 38 | -------------------------------------------------------------------------------- /examples/cloud-grpc-client/src/main/java/net/devh/boot/grpc/examples/cloud/client/CloudClientApplication.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2023 The gRPC-Spring Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.devh.boot.grpc.examples.cloud.client; 18 | 19 | import org.springframework.boot.SpringApplication; 20 | import org.springframework.boot.autoconfigure.SpringBootApplication; 21 | import org.springframework.cloud.client.discovery.EnableDiscoveryClient; 22 | 23 | /** 24 | * Example grpc client application using cloud discovery. 25 | */ 26 | @EnableDiscoveryClient 27 | @SpringBootApplication 28 | public class CloudClientApplication { 29 | 30 | /** 31 | * Starts the grpc cloud discovery client application. 32 | * 33 | * @param args The arguments to pass to the application. 34 | */ 35 | public static void main(final String... args) { 36 | SpringApplication.run(CloudClientApplication.class, args); 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /examples/cloud-grpc-client/src/main/java/net/devh/boot/grpc/examples/cloud/client/GlobalInterceptorConfiguration.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2023 The gRPC-Spring Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.devh.boot.grpc.examples.cloud.client; 18 | 19 | import org.springframework.context.annotation.Configuration; 20 | 21 | import io.grpc.ClientInterceptor; 22 | import net.devh.boot.grpc.client.interceptor.GrpcGlobalClientInterceptor; 23 | 24 | /** 25 | * Example configuration class that adds a {@link ClientInterceptor} to the global interceptor list. 26 | */ 27 | @Configuration(proxyBeanMethods = false) 28 | public class GlobalInterceptorConfiguration { 29 | 30 | /** 31 | * Creates a new {@link LogGrpcInterceptor} bean and adds it to the global interceptor list. As an alternative you 32 | * can directly annotate the {@code LogGrpcInterceptor} class and it will automatically be picked up by spring's 33 | * classpath scanning. 34 | * 35 | * @return The newly created bean. 36 | */ 37 | @GrpcGlobalClientInterceptor 38 | LogGrpcInterceptor logClientInterceptor() { 39 | return new LogGrpcInterceptor(); 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /examples/cloud-grpc-client/src/main/java/net/devh/boot/grpc/examples/cloud/client/GrpcClientController.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2023 The gRPC-Spring Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.devh.boot.grpc.examples.cloud.client; 18 | 19 | import org.springframework.beans.factory.annotation.Autowired; 20 | import org.springframework.web.bind.annotation.RequestMapping; 21 | import org.springframework.web.bind.annotation.RequestParam; 22 | import org.springframework.web.bind.annotation.RestController; 23 | 24 | /** 25 | * Optional demo controller making the grpc service accessible via browser requests. 26 | */ 27 | @RestController 28 | public class GrpcClientController { 29 | 30 | @Autowired 31 | private GrpcClientService grpcClientService; 32 | 33 | @RequestMapping("/") 34 | public String printMessage(@RequestParam(defaultValue = "Michael") final String name) { 35 | return this.grpcClientService.sendMessage(name); 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /examples/cloud-grpc-client/src/main/java/net/devh/boot/grpc/examples/cloud/client/GrpcClientService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2023 The gRPC-Spring Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.devh.boot.grpc.examples.cloud.client; 18 | 19 | import org.springframework.stereotype.Service; 20 | 21 | import io.grpc.StatusRuntimeException; 22 | import lombok.extern.slf4j.Slf4j; 23 | import net.devh.boot.grpc.client.inject.GrpcClient; 24 | import net.devh.boot.grpc.examples.lib.HelloReply; 25 | import net.devh.boot.grpc.examples.lib.HelloRequest; 26 | import net.devh.boot.grpc.examples.lib.SimpleGrpc.SimpleBlockingStub; 27 | 28 | /** 29 | * Example class demonstrating the usage of {@link GrpcClient}s inside an application. 30 | */ 31 | @Service 32 | @Slf4j 33 | public class GrpcClientService { 34 | 35 | @GrpcClient("cloud-grpc-server") 36 | private SimpleBlockingStub simpleStub; 37 | 38 | public String sendMessage(final String name) { 39 | try { 40 | final HelloReply response = this.simpleStub.sayHello(HelloRequest.newBuilder().setName(name).build()); 41 | return response.getMessage(); 42 | } catch (final StatusRuntimeException e) { 43 | log.error("Request failed", e); 44 | return "FAILED with " + e.getStatus().getCode(); 45 | } 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /examples/cloud-grpc-client/src/main/resources/application-consul.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | cloud: 3 | consul: 4 | discovery: 5 | register: false 6 | # hostname: localhost 7 | # port: 8500 8 | -------------------------------------------------------------------------------- /examples/cloud-grpc-client/src/main/resources/application-eureka.yml: -------------------------------------------------------------------------------- 1 | eureka: 2 | instance: 3 | prefer-ip-address: true 4 | status-page-url-path: /actuator/info 5 | health-check-url-path: /actuator/health 6 | client: 7 | register-with-eureka: false 8 | fetch-registry: true 9 | service-url: 10 | defaultZone: http://localhost:8761/eureka/ 11 | -------------------------------------------------------------------------------- /examples/cloud-grpc-client/src/main/resources/application-nacos.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | cloud: 3 | nacos: 4 | discovery: 5 | register-enabled: false 6 | # server-addr: localhost:8848 7 | -------------------------------------------------------------------------------- /examples/cloud-grpc-client/src/main/resources/application-zookeeper.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | cloud: 3 | zookeeper: 4 | # connect-string: localhost:2181 5 | discovery: 6 | registry: false 7 | -------------------------------------------------------------------------------- /examples/cloud-grpc-client/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8080 3 | spring: 4 | application: 5 | name: cloud-grpc-client 6 | grpc: 7 | client: 8 | cloud-grpc-server: 9 | address: 'discovery:///cloud-grpc-server' 10 | enableKeepAlive: true 11 | keepAliveWithoutCalls: true 12 | negotiationType: plaintext 13 | -------------------------------------------------------------------------------- /examples/cloud-grpc-server/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'org.springframework.boot' 3 | } 4 | 5 | def discoveryProvider = project.findProperty('discovery') ?: 'consul'; 6 | 7 | dependencies { 8 | switch (discoveryProvider) { 9 | case "nacos": { 10 | implementation 'com.alibaba.cloud:spring-cloud-starter-alibaba-nacos-discovery' 11 | break; 12 | } 13 | case "consul": { 14 | implementation 'org.springframework.cloud:spring-cloud-starter-consul-discovery' 15 | break; 16 | } 17 | case "eureka": { 18 | implementation 'org.springframework.cloud:spring-cloud-starter-netflix-eureka-client' 19 | break; 20 | } 21 | case "zookeeper": { 22 | implementation 'org.springframework.cloud:spring-cloud-starter-zookeeper-discovery' 23 | break; 24 | } 25 | } 26 | 27 | implementation project(':grpc-server-spring-boot-starter') // Replace with actual dependency "net.devh:grpc-server-spring-boot-starter:${springBootGrpcVersion}" 28 | implementation project(':examples:grpc-lib') // Replace with your grpc interface spec 29 | 30 | // For demonstration only 31 | implementation 'org.springframework.boot:spring-boot-starter-actuator' 32 | implementation 'org.springframework.boot:spring-boot-starter-web' 33 | } 34 | 35 | bootRun { 36 | args = ["--spring.profiles.active=" + discoveryProvider] 37 | } 38 | -------------------------------------------------------------------------------- /examples/cloud-grpc-server/src/main/java/net/devh/boot/grpc/examples/cloud/server/CloudServerApplication.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2023 The gRPC-Spring Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.devh.boot.grpc.examples.cloud.server; 18 | 19 | import org.springframework.boot.SpringApplication; 20 | import org.springframework.boot.autoconfigure.SpringBootApplication; 21 | import org.springframework.cloud.client.discovery.EnableDiscoveryClient; 22 | 23 | /** 24 | * Example grpc service application supporting cloud discovery. 25 | */ 26 | @EnableDiscoveryClient 27 | @SpringBootApplication 28 | public class CloudServerApplication { 29 | 30 | /** 31 | * Starts the grpc cloud server application. 32 | * 33 | * @param args The arguments to pass to the application. 34 | */ 35 | public static void main(final String... args) { 36 | SpringApplication.run(CloudServerApplication.class, args); 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /examples/cloud-grpc-server/src/main/java/net/devh/boot/grpc/examples/cloud/server/GlobalInterceptorConfiguration.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2023 The gRPC-Spring Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.devh.boot.grpc.examples.cloud.server; 18 | 19 | import org.springframework.context.annotation.Configuration; 20 | 21 | import io.grpc.ServerInterceptor; 22 | import net.devh.boot.grpc.server.interceptor.GrpcGlobalServerInterceptor; 23 | 24 | /** 25 | * Example configuration class that adds a {@link ServerInterceptor} to the global interceptor list. 26 | */ 27 | @Configuration(proxyBeanMethods = false) 28 | public class GlobalInterceptorConfiguration { 29 | 30 | /** 31 | * Creates a new {@link LogGrpcInterceptor} bean and adds it to the global interceptor list. As an alternative you 32 | * can directly annotate the {@code LogGrpcInterceptor} class and it will automatically be picked up by spring's 33 | * classpath scanning. 34 | * 35 | * @return The newly created bean. 36 | */ 37 | @GrpcGlobalServerInterceptor 38 | LogGrpcInterceptor logServerInterceptor() { 39 | return new LogGrpcInterceptor(); 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /examples/cloud-grpc-server/src/main/java/net/devh/boot/grpc/examples/cloud/server/GrpcServerService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2023 The gRPC-Spring Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.devh.boot.grpc.examples.cloud.server; 18 | 19 | import io.grpc.stub.StreamObserver; 20 | import net.devh.boot.grpc.examples.lib.HelloReply; 21 | import net.devh.boot.grpc.examples.lib.HelloRequest; 22 | import net.devh.boot.grpc.examples.lib.SimpleGrpc; 23 | import net.devh.boot.grpc.server.service.GrpcService; 24 | 25 | /** 26 | * Example grpc server service implementation class. 27 | */ 28 | @GrpcService 29 | public class GrpcServerService extends SimpleGrpc.SimpleImplBase { 30 | 31 | @Override 32 | public void sayHello(final HelloRequest req, final StreamObserver responseObserver) { 33 | final HelloReply reply = HelloReply.newBuilder().setMessage("Hello ==> " + req.getName()).build(); 34 | responseObserver.onNext(reply); 35 | responseObserver.onCompleted(); 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /examples/cloud-grpc-server/src/main/java/net/devh/boot/grpc/examples/cloud/server/LogGrpcInterceptor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2023 The gRPC-Spring Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.devh.boot.grpc.examples.cloud.server; 18 | 19 | import org.slf4j.Logger; 20 | import org.slf4j.LoggerFactory; 21 | 22 | import io.grpc.Metadata; 23 | import io.grpc.ServerCall; 24 | import io.grpc.ServerCallHandler; 25 | import io.grpc.ServerInterceptor; 26 | import net.devh.boot.grpc.server.interceptor.GrpcGlobalServerInterceptor; 27 | 28 | /** 29 | * Example {@link ServerInterceptor} that logs all called methods. In this example it is added to Spring's application 30 | * context via {@link GlobalInterceptorConfiguration}, but is also possible to directly annotate this class with 31 | * {@link GrpcGlobalServerInterceptor}. 32 | */ 33 | // @GrpcGlobalServerInterceptor 34 | public class LogGrpcInterceptor implements ServerInterceptor { 35 | 36 | private static final Logger log = LoggerFactory.getLogger(LogGrpcInterceptor.class); 37 | 38 | @Override 39 | public ServerCall.Listener interceptCall( 40 | ServerCall serverCall, 41 | Metadata metadata, 42 | ServerCallHandler serverCallHandler) { 43 | 44 | log.info(serverCall.getMethodDescriptor().getFullMethodName()); 45 | return serverCallHandler.startCall(serverCall, metadata); 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /examples/cloud-grpc-server/src/main/resources/application-consul.yml: -------------------------------------------------------------------------------- 1 | #spring: 2 | # cloud: 3 | # consul: 4 | # discovery: 5 | # register: true 6 | # hostname: localhost 7 | # port: 8500 8 | -------------------------------------------------------------------------------- /examples/cloud-grpc-server/src/main/resources/application-eureka.yml: -------------------------------------------------------------------------------- 1 | eureka: 2 | instance: 3 | prefer-ip-address: true 4 | client: 5 | register-with-eureka: true 6 | fetch-registry: false 7 | service-url: 8 | defaultZone: http://localhost:8761/eureka/ 9 | -------------------------------------------------------------------------------- /examples/cloud-grpc-server/src/main/resources/application-nacos.yml: -------------------------------------------------------------------------------- 1 | #spring: 2 | # cloud: 3 | # nacos: 4 | # discovery: 5 | # register-enabled: true 6 | # server-addr: localhost:8848 7 | -------------------------------------------------------------------------------- /examples/cloud-grpc-server/src/main/resources/application-zookeeper.yml: -------------------------------------------------------------------------------- 1 | #spring: 2 | # cloud: 3 | # zookeeper: 4 | # connect-string: localhost:2181 5 | # discovery: 6 | # register: true 7 | -------------------------------------------------------------------------------- /examples/cloud-grpc-server/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 58080 3 | 4 | spring: 5 | application: 6 | name: cloud-grpc-server 7 | 8 | grpc: 9 | server: 10 | port: 0 11 | -------------------------------------------------------------------------------- /examples/grpc-lib/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'com.google.protobuf' 3 | } 4 | 5 | dependencies { 6 | implementation 'io.grpc:grpc-netty-shaded' 7 | implementation 'io.grpc:grpc-protobuf' 8 | implementation 'io.grpc:grpc-stub' 9 | if (JavaVersion.current().isJava9Compatible()) { 10 | // Workaround for @javax.annotation.Generated 11 | // see: https://github.com/grpc/grpc-java/issues/3633 12 | compileOnly 'org.apache.tomcat:annotations-api:6.0.53' 13 | annotationProcessor "jakarta.annotation:jakarta.annotation-api" 14 | } 15 | } 16 | 17 | protobuf { 18 | protoc { 19 | artifact = "com.google.protobuf:protoc:${protobufVersion}" 20 | } 21 | generatedFilesBaseDir = "$projectDir/src/generated" 22 | clean { 23 | delete generatedFilesBaseDir 24 | } 25 | plugins { 26 | grpc { 27 | artifact = "io.grpc:protoc-gen-grpc-java:${grpcVersion}" 28 | } 29 | } 30 | generateProtoTasks { 31 | all()*.plugins { 32 | grpc {} 33 | } 34 | } 35 | } 36 | 37 | eclipse { 38 | classpath { 39 | file.beforeMerged { cp -> 40 | def generatedGrpcFolder = new org.gradle.plugins.ide.eclipse.model.SourceFolder('src/generated/main/grpc', null); 41 | generatedGrpcFolder.entryAttributes['ignore_optional_problems'] = 'true'; 42 | cp.entries.add( generatedGrpcFolder ); 43 | def generatedJavaFolder = new org.gradle.plugins.ide.eclipse.model.SourceFolder('src/generated/main/java', null); 44 | generatedJavaFolder.entryAttributes['ignore_optional_problems'] = 'true'; 45 | cp.entries.add( generatedJavaFolder ); 46 | } 47 | } 48 | } 49 | 50 | idea { 51 | module { 52 | sourceDirs += file('src/generated/main/java') 53 | sourceDirs += file('src/generated/main/grpc') 54 | generatedSourceDirs += file('src/generated/main/java') 55 | generatedSourceDirs += file('src/generated/main/grpc') 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /examples/grpc-lib/src/main/proto/helloworld.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | option java_multiple_files = true; 4 | option java_package = "net.devh.boot.grpc.examples.lib"; 5 | option java_outer_classname = "HelloWorldProto"; 6 | 7 | // The greeting service definition. 8 | service Simple { 9 | // Sends a greeting 10 | rpc SayHello (HelloRequest) returns (HelloReply) { 11 | } 12 | } 13 | 14 | // The request message containing the user's name. 15 | message HelloRequest { 16 | string name = 1; 17 | } 18 | 19 | // The response message containing the greetings 20 | message HelloReply { 21 | string message = 1; 22 | } 23 | -------------------------------------------------------------------------------- /examples/grpc-observability/backend/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM eclipse-temurin:17-jdk-alpine 2 | COPY build/libs/backend.jar backend.jar 3 | ENTRYPOINT ["java","-jar","/backend.jar"] 4 | -------------------------------------------------------------------------------- /examples/grpc-observability/backend/backend.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2023 gRPC Authors 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | apiVersion: apps/v1 16 | kind: Deployment 17 | metadata: 18 | name: backend 19 | spec: 20 | replicas: 1 21 | selector: 22 | matchLabels: 23 | app: backend 24 | template: 25 | metadata: 26 | labels: 27 | app: backend 28 | monitor: prometheus 29 | spec: 30 | containers: 31 | - name: backend 32 | # Please upload the docker image of grpc-observability/grpc-spring-example-backend to an image registry, such as https://cloud.google.com/artifact-registry. 33 | image: 34 | ports: 35 | - name: monitoring 36 | containerPort: 8081 37 | - name: grpc 38 | containerPort: 9091 39 | --- 40 | apiVersion: v1 41 | kind: Service 42 | metadata: 43 | name: backend 44 | spec: 45 | clusterIP: None 46 | selector: 47 | app: backend 48 | ports: 49 | - name: monitoring 50 | port: 8081 51 | - name: grpc 52 | port: 9091 53 | -------------------------------------------------------------------------------- /examples/grpc-observability/backend/build.gradle: -------------------------------------------------------------------------------- 1 | // Copyright 2023 The gRPC-GCP-Mobile Authors 2 | // All rights reserved. 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | // 16 | plugins { 17 | id 'org.springframework.boot' 18 | } 19 | 20 | dependencies { 21 | implementation project(':examples:grpc-observability:proto') 22 | implementation project(':grpc-server-spring-boot-starter') 23 | implementation 'org.springframework.boot:spring-boot-starter-actuator' 24 | implementation "org.springframework.boot:spring-boot-starter-web" 25 | implementation 'io.micrometer:micrometer-registry-prometheus' 26 | } 27 | -------------------------------------------------------------------------------- /examples/grpc-observability/backend/src/main/java/net/devh/boot/grpc/examples/observability/backend/BackendApplication.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2023 The gRPC-Spring Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.devh.boot.grpc.examples.observability.backend; 18 | 19 | import org.springframework.boot.SpringApplication; 20 | import org.springframework.boot.autoconfigure.SpringBootApplication; 21 | 22 | @SpringBootApplication 23 | public class BackendApplication { 24 | 25 | public static void main(String[] args) { 26 | SpringApplication.run(BackendApplication.class, args); 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /examples/grpc-observability/backend/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | # Port serves the monitoring traffic. 2 | server.port=8081 3 | # Expose the prometheus metrics via the monitoring port. 4 | # By default, expose on `/actuator/prometheus`. 5 | management.endpoints.web.exposure.include=prometheus 6 | # Port serves the gRPC traffic. 7 | grpc.server.port=9091 8 | -------------------------------------------------------------------------------- /examples/grpc-observability/frontend/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM eclipse-temurin:17-jdk-alpine 2 | COPY build/libs/frontend.jar frontend.jar 3 | ENTRYPOINT ["java","-jar","/frontend.jar"] 4 | -------------------------------------------------------------------------------- /examples/grpc-observability/frontend/build.gradle: -------------------------------------------------------------------------------- 1 | // Copyright 2023 The gRPC-GCP-Mobile Authors 2 | // All rights reserved. 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | // 16 | plugins { 17 | id 'org.springframework.boot' 18 | } 19 | 20 | dependencies { 21 | implementation project(':examples:grpc-observability:proto') 22 | implementation project(':grpc-client-spring-boot-starter') 23 | implementation 'org.springframework.boot:spring-boot-starter-actuator' 24 | implementation "org.springframework.boot:spring-boot-starter-web" 25 | implementation 'io.micrometer:micrometer-registry-prometheus' 26 | } 27 | -------------------------------------------------------------------------------- /examples/grpc-observability/frontend/frontend.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2023 gRPC Authors 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | apiVersion: apps/v1 16 | kind: Deployment 17 | metadata: 18 | name: frontend 19 | spec: 20 | replicas: 1 21 | selector: 22 | matchLabels: 23 | app: frontend 24 | template: 25 | metadata: 26 | labels: 27 | app: frontend 28 | monitor: prometheus 29 | spec: 30 | containers: 31 | - name: frontend 32 | # Please upload the docker image of grpc-observability/grpc-spring-example-frontend to an image registry, such as https://cloud.google.com/artifact-registry. 33 | image: 34 | imagePullPolicy: Always 35 | ports: 36 | - name: monitoring 37 | containerPort: 8080 38 | --- 39 | apiVersion: v1 40 | kind: Service 41 | metadata: 42 | name: frontend 43 | spec: 44 | clusterIP: None 45 | selector: 46 | app: frontend 47 | ports: 48 | - name: monitoring 49 | port: 8080 50 | -------------------------------------------------------------------------------- /examples/grpc-observability/frontend/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | # Port serves the monitoring traffic. 2 | server.port=8080 3 | # Expose the prometheus metrics via the monitoring port. 4 | # By default, expose on `/actuator/prometheus`. 5 | management.endpoints.web.exposure.include=prometheus,configprops,env,info 6 | management.endpoint.env.show-values=ALWAYS 7 | management.endpoint.configprops.show-values=ALWAYS 8 | # The backend service address, for local testing. 9 | grpc.client.backend.address=static://localhost:9091 10 | # Teh backend service address, for kubernetes. 11 | # grpc.client.backend.address=dns:///backend.default.svc.cluster.local:9091 12 | grpc.client.backend.negotiationType=PLAINTEXT 13 | -------------------------------------------------------------------------------- /examples/grpc-observability/pod_monitoring.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: monitoring.googleapis.com/v1 2 | kind: PodMonitoring 3 | metadata: 4 | name: prometheus 5 | spec: 6 | selector: 7 | matchLabels: 8 | monitor: prometheus 9 | endpoints: 10 | - port: monitoring 11 | path: /actuator/prometheus 12 | interval: 30s 13 | -------------------------------------------------------------------------------- /examples/grpc-observability/proto/build.gradle: -------------------------------------------------------------------------------- 1 | // Copyright 2023 The gRPC-GCP-Mobile Authors 2 | // All rights reserved. 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | // 16 | plugins { 17 | id 'com.google.protobuf' 18 | } 19 | 20 | protobuf { 21 | protoc { 22 | artifact = "com.google.protobuf:protoc:${protobufVersion}" 23 | } 24 | plugins { 25 | grpc { 26 | artifact = "io.grpc:protoc-gen-grpc-java:${grpcVersion}" 27 | } 28 | } 29 | generateProtoTasks { 30 | all()*.plugins { 31 | grpc {} 32 | } 33 | } 34 | } 35 | 36 | dependencies { 37 | implementation 'io.grpc:grpc-protobuf' 38 | implementation 'io.grpc:grpc-stub' 39 | if (JavaVersion.current().isJava9Compatible()) { 40 | // Workaround for @javax.annotation.Generated 41 | // see: https://github.com/grpc/grpc-java/issues/3633 42 | implementation 'javax.annotation:javax.annotation-api:1.3.1' 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /examples/grpc-observability/proto/src/main/proto/backend.proto: -------------------------------------------------------------------------------- 1 | // Copyright 2023 The gRPC-GCP-Mobile Authors 2 | // All rights reserved. 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | syntax = "proto3"; 17 | 18 | package net.devh.boot.grpc.examples.observability.proto; 19 | 20 | option java_package = "net.devh.boot.grpc.examples.observability.proto"; 21 | option java_outer_classname = "ExampleServiceProto"; 22 | option java_multiple_files = true; 23 | 24 | service ExampleService { 25 | rpc UnaryRpc (UnaryRequest) returns (UnaryResponse) {} 26 | rpc ClientStreamingRpc (stream ClientStreamingRequest) returns (ClientStreamingResponse) {} 27 | rpc ServerStreamingRpc (ServerStreamingRequest) returns (stream ServerStreamingResponse) {} 28 | rpc BidiStreamingRpc (stream BidiStreamingRequest) returns (stream BidiStreamingResponse) {} 29 | } 30 | 31 | message UnaryRequest { 32 | string message = 1; 33 | } 34 | 35 | message UnaryResponse { 36 | string message = 1; 37 | } 38 | 39 | message ClientStreamingRequest { 40 | string message = 1; 41 | } 42 | 43 | message ClientStreamingResponse { 44 | string message = 1; 45 | } 46 | 47 | message ServerStreamingRequest { 48 | string message = 1; 49 | } 50 | 51 | message ServerStreamingResponse { 52 | string message = 1; 53 | } 54 | 55 | message BidiStreamingRequest { 56 | string message = 1; 57 | } 58 | 59 | message BidiStreamingResponse { 60 | string message = 1; 61 | } 62 | -------------------------------------------------------------------------------- /examples/local-grpc-client/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'org.springframework.boot' 3 | } 4 | 5 | dependencies { 6 | implementation 'org.springframework.boot:spring-boot-starter-web' 7 | implementation project(':grpc-client-spring-boot-starter') // replace to implementation("net.devh:grpc-client-spring-boot-starter:${springBootGrpcVersion}") 8 | implementation project(':examples:grpc-lib') 9 | } 10 | -------------------------------------------------------------------------------- /examples/local-grpc-client/src/main/java/net/devh/boot/grpc/examples/local/client/GlobalClientInterceptorConfiguration.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2023 The gRPC-Spring Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.devh.boot.grpc.examples.local.client; 18 | 19 | import org.springframework.context.annotation.Configuration; 20 | import org.springframework.core.Ordered; 21 | import org.springframework.core.annotation.Order; 22 | 23 | import net.devh.boot.grpc.client.interceptor.GrpcGlobalClientInterceptor; 24 | 25 | @Order(Ordered.LOWEST_PRECEDENCE) 26 | @Configuration(proxyBeanMethods = false) 27 | public class GlobalClientInterceptorConfiguration { 28 | 29 | @GrpcGlobalClientInterceptor 30 | LogGrpcInterceptor logClientInterceptor() { 31 | return new LogGrpcInterceptor(); 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /examples/local-grpc-client/src/main/java/net/devh/boot/grpc/examples/local/client/GrpcClientController.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2023 The gRPC-Spring Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.devh.boot.grpc.examples.local.client; 18 | 19 | import org.springframework.beans.factory.annotation.Autowired; 20 | import org.springframework.web.bind.annotation.RequestMapping; 21 | import org.springframework.web.bind.annotation.RequestParam; 22 | import org.springframework.web.bind.annotation.RestController; 23 | 24 | /** 25 | * @author Michael (yidongnan@gmail.com) 26 | * @since 2016/12/4 27 | */ 28 | @RestController 29 | public class GrpcClientController { 30 | 31 | @Autowired 32 | private GrpcClientService grpcClientService; 33 | 34 | @RequestMapping("/") 35 | public String printMessage(@RequestParam(defaultValue = "Michael") String name) { 36 | return grpcClientService.sendMessage(name); 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /examples/local-grpc-client/src/main/java/net/devh/boot/grpc/examples/local/client/GrpcClientService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2023 The gRPC-Spring Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.devh.boot.grpc.examples.local.client; 18 | 19 | import org.springframework.stereotype.Service; 20 | 21 | import io.grpc.StatusRuntimeException; 22 | import net.devh.boot.grpc.client.inject.GrpcClient; 23 | import net.devh.boot.grpc.examples.lib.HelloReply; 24 | import net.devh.boot.grpc.examples.lib.HelloRequest; 25 | import net.devh.boot.grpc.examples.lib.SimpleGrpc.SimpleBlockingStub; 26 | 27 | /** 28 | * @author Michael (yidongnan@gmail.com) 29 | * @since 2016/11/8 30 | */ 31 | @Service 32 | public class GrpcClientService { 33 | 34 | @GrpcClient("local-grpc-server") 35 | private SimpleBlockingStub simpleStub; 36 | 37 | public String sendMessage(final String name) { 38 | try { 39 | final HelloReply response = this.simpleStub.sayHello(HelloRequest.newBuilder().setName(name).build()); 40 | return response.getMessage(); 41 | } catch (final StatusRuntimeException e) { 42 | return "FAILED with " + e.getStatus().getCode().name(); 43 | } 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /examples/local-grpc-client/src/main/java/net/devh/boot/grpc/examples/local/client/LocalGrpcClientApplication.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2023 The gRPC-Spring Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.devh.boot.grpc.examples.local.client; 18 | 19 | import org.springframework.boot.SpringApplication; 20 | import org.springframework.boot.autoconfigure.SpringBootApplication; 21 | 22 | /** 23 | * @author Michael (yidongnan@gmail.com) 24 | * @since 2016/11/8 25 | */ 26 | @SpringBootApplication 27 | public class LocalGrpcClientApplication { 28 | 29 | public static void main(String[] args) { 30 | SpringApplication.run(LocalGrpcClientApplication.class, args); 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /examples/local-grpc-client/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8080 3 | spring: 4 | application: 5 | name: local-grpc-client 6 | 7 | grpc: 8 | client: 9 | local-grpc-server: 10 | address: 'static://127.0.0.1:9898' 11 | enableKeepAlive: true 12 | keepAliveWithoutCalls: true 13 | negotiationType: plaintext 14 | -------------------------------------------------------------------------------- /examples/local-grpc-server/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'org.springframework.boot' 3 | } 4 | 5 | dependencies { 6 | implementation 'org.springframework.boot:spring-boot-starter' 7 | implementation project(':grpc-server-spring-boot-starter') // replace to implementation("net.devh:grpc-server-spring-boot-starter:${springBootGrpcVersion}") 8 | implementation project(':examples:grpc-lib') 9 | } 10 | -------------------------------------------------------------------------------- /examples/local-grpc-server/src/main/java/net/devh/boot/grpc/examples/local/server/GlobalInterceptorConfiguration.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2023 The gRPC-Spring Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.devh.boot.grpc.examples.local.server; 18 | 19 | import org.springframework.context.annotation.Configuration; 20 | 21 | import net.devh.boot.grpc.server.interceptor.GrpcGlobalServerInterceptor; 22 | 23 | @Configuration(proxyBeanMethods = false) 24 | public class GlobalInterceptorConfiguration { 25 | 26 | @GrpcGlobalServerInterceptor 27 | LogGrpcInterceptor logServerInterceptor() { 28 | return new LogGrpcInterceptor(); 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /examples/local-grpc-server/src/main/java/net/devh/boot/grpc/examples/local/server/GrpcServerService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2023 The gRPC-Spring Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.devh.boot.grpc.examples.local.server; 18 | 19 | import io.grpc.stub.StreamObserver; 20 | import net.devh.boot.grpc.examples.lib.HelloReply; 21 | import net.devh.boot.grpc.examples.lib.HelloRequest; 22 | import net.devh.boot.grpc.examples.lib.SimpleGrpc; 23 | import net.devh.boot.grpc.server.service.GrpcService; 24 | 25 | /** 26 | * @author Michael (yidongnan@gmail.com) 27 | * @since 2016/11/8 28 | */ 29 | 30 | @GrpcService 31 | public class GrpcServerService extends SimpleGrpc.SimpleImplBase { 32 | 33 | @Override 34 | public void sayHello(HelloRequest req, StreamObserver responseObserver) { 35 | HelloReply reply = HelloReply.newBuilder().setMessage("Hello ==> " + req.getName()).build(); 36 | responseObserver.onNext(reply); 37 | responseObserver.onCompleted(); 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /examples/local-grpc-server/src/main/java/net/devh/boot/grpc/examples/local/server/LocalGrpcServerApplication.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2023 The gRPC-Spring Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.devh.boot.grpc.examples.local.server; 18 | 19 | import org.springframework.boot.SpringApplication; 20 | import org.springframework.boot.autoconfigure.SpringBootApplication; 21 | 22 | /** 23 | * @author Michael (yidongnan@gmail.com) 24 | * @since 2016/11/8 25 | */ 26 | @SpringBootApplication 27 | public class LocalGrpcServerApplication { 28 | 29 | public static void main(String[] args) { 30 | SpringApplication.run(LocalGrpcServerApplication.class, args); 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /examples/local-grpc-server/src/main/java/net/devh/boot/grpc/examples/local/server/LogGrpcInterceptor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2023 The gRPC-Spring Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.devh.boot.grpc.examples.local.server; 18 | 19 | import org.slf4j.Logger; 20 | import org.slf4j.LoggerFactory; 21 | 22 | import io.grpc.Metadata; 23 | import io.grpc.ServerCall; 24 | import io.grpc.ServerCallHandler; 25 | import io.grpc.ServerInterceptor; 26 | 27 | /** 28 | * @author Michael (yidongnan@gmail.com) 29 | * @since 2016/12/6 30 | */ 31 | public class LogGrpcInterceptor implements ServerInterceptor { 32 | 33 | private static final Logger log = LoggerFactory.getLogger(LogGrpcInterceptor.class); 34 | 35 | @Override 36 | public ServerCall.Listener interceptCall(ServerCall serverCall, Metadata metadata, 37 | ServerCallHandler serverCallHandler) { 38 | log.info(serverCall.getMethodDescriptor().getFullMethodName()); 39 | return serverCallHandler.startCall(serverCall, metadata); 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /examples/local-grpc-server/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | application: 3 | name: local-grpc-server 4 | grpc: 5 | server: 6 | port: 9898 7 | -------------------------------------------------------------------------------- /examples/security-grpc-client/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'org.springframework.boot' 3 | } 4 | 5 | dependencies { 6 | implementation 'org.springframework.boot:spring-boot-starter-web' 7 | implementation 'org.springframework.security:spring-security-core' 8 | implementation project(':grpc-client-spring-boot-starter') // replace to implementation "net.devh:grpc-client-spring-boot-starter:${springBootGrpcVersion}" 9 | implementation project(':examples:grpc-lib') 10 | } 11 | -------------------------------------------------------------------------------- /examples/security-grpc-client/src/main/java/net/devh/boot/grpc/examples/security/client/SecurityConfiguration.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2023 The gRPC-Spring Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.devh.boot.grpc.examples.security.client; 18 | 19 | import org.springframework.beans.factory.annotation.Value; 20 | import org.springframework.context.annotation.Bean; 21 | import org.springframework.context.annotation.Configuration; 22 | 23 | import io.grpc.CallCredentials; 24 | import net.devh.boot.grpc.client.inject.StubTransformer; 25 | import net.devh.boot.grpc.client.security.CallCredentialsHelper; 26 | 27 | /** 28 | * The security configuration for the client. In this case we assume that we use the same passwords for all stubs. If 29 | * you need per stub credentials you can delete the grpcCredentials and define a {@link StubTransformer} yourself. 30 | * 31 | * @author Daniel Theuke (daniel.theuke@heuboe.de) 32 | * @see CallCredentialsHelper 33 | */ 34 | @Configuration(proxyBeanMethods = false) 35 | public class SecurityConfiguration { 36 | 37 | @Value("${auth.username}") 38 | private String username; 39 | 40 | @Bean 41 | // Create credentials for username + password. 42 | CallCredentials grpcCredentials() { 43 | return CallCredentialsHelper.basicAuth(this.username, this.username + "Password"); 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /examples/security-grpc-client/src/main/java/net/devh/boot/grpc/examples/security/client/SecurityGrpcClientApplication.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2023 The gRPC-Spring Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.devh.boot.grpc.examples.security.client; 18 | 19 | import org.springframework.boot.SpringApplication; 20 | import org.springframework.boot.autoconfigure.SpringBootApplication; 21 | 22 | /** 23 | * An example client application that demonstrates basic auth security. 24 | * 25 | * @author Daniel Theuke (daniel.theuke@heuboe.de) 26 | */ 27 | @SpringBootApplication 28 | public class SecurityGrpcClientApplication { 29 | 30 | public static void main(final String[] args) { 31 | SpringApplication.run(SecurityGrpcClientApplication.class, args); 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /examples/security-grpc-client/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8080 3 | spring: 4 | application: 5 | name: security-grpc-client 6 | # auth.username: guest 7 | auth.username: user 8 | # auth.username: unknown 9 | grpc: 10 | client: 11 | security-grpc-server: 12 | address: 'static://127.0.0.1:9090' 13 | enableKeepAlive: true 14 | keepAliveWithoutCalls: true 15 | negotiationType: plaintext 16 | -------------------------------------------------------------------------------- /examples/security-grpc-server/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'org.springframework.boot' 3 | } 4 | 5 | dependencies { 6 | implementation 'org.springframework.boot:spring-boot-starter' 7 | implementation 'org.springframework.security:spring-security-config' 8 | implementation project(':grpc-server-spring-boot-starter') // replace to implementation("net.devh:grpc-server-spring-boot-starter:${springBootGrpcVersion}") 9 | implementation project(':examples:grpc-lib') 10 | } 11 | -------------------------------------------------------------------------------- /examples/security-grpc-server/src/main/java/net/devh/boot/grpc/examples/security/server/GrpcServerService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2023 The gRPC-Spring Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.devh.boot.grpc.examples.security.server; 18 | 19 | import org.springframework.security.access.annotation.Secured; 20 | 21 | import io.grpc.stub.StreamObserver; 22 | import net.devh.boot.grpc.examples.lib.HelloReply; 23 | import net.devh.boot.grpc.examples.lib.HelloRequest; 24 | import net.devh.boot.grpc.examples.lib.SimpleGrpc; 25 | import net.devh.boot.grpc.server.service.GrpcService; 26 | 27 | /** 28 | * An example service that checks the user's authentication. 29 | * 30 | * @author Daniel Theuke (daniel.theuke@heuboe.de) 31 | */ 32 | @GrpcService 33 | public class GrpcServerService extends SimpleGrpc.SimpleImplBase { 34 | 35 | // A grpc method that requests the user to be authenticated and have the role "ROLE_GREET". 36 | @Override 37 | @Secured("ROLE_GREET") 38 | public void sayHello(final HelloRequest req, final StreamObserver responseObserver) { 39 | final HelloReply reply = HelloReply.newBuilder().setMessage("Hello ==> " + req.getName()).build(); 40 | responseObserver.onNext(reply); 41 | responseObserver.onCompleted(); 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /examples/security-grpc-server/src/main/java/net/devh/boot/grpc/examples/security/server/SecurityGrpcServerApplication.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2023 The gRPC-Spring Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.devh.boot.grpc.examples.security.server; 18 | 19 | import org.springframework.boot.SpringApplication; 20 | import org.springframework.boot.autoconfigure.SpringBootApplication; 21 | 22 | /** 23 | * An example server application that demonstrates basic auth security. 24 | * 25 | * @author Daniel Theuke (daniel.theuke@heuboe.de) 26 | */ 27 | @SpringBootApplication 28 | public class SecurityGrpcServerApplication { 29 | 30 | public static void main(final String[] args) { 31 | SpringApplication.run(SecurityGrpcServerApplication.class, args); 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /examples/security-grpc-server/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | application: 3 | name: security-grpc-server 4 | grpc: 5 | server: 6 | port: 9090 7 | -------------------------------------------------------------------------------- /extra/eclipse/eclipse.importorder: -------------------------------------------------------------------------------- 1 | #Organize Import Order 2 | 0=java 3 | 1=javax 4 | 2=org 5 | 3=com 6 | 4= -------------------------------------------------------------------------------- /extra/spotless/license.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-$YEAR The gRPC-Spring Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | org.gradle.caching=true 2 | # It is not possible to use parallel, 3 | # because tests in multiple modules require the same ports 4 | #org.gradle.parallel=true 5 | org.gradle.vfs.watch=true 6 | org.gradle.daemon=true 7 | 8 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/grpc-ecosystem/grpc-spring/b83afe68cef63edc7dfeec694bc279956bbc8c3d/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip 4 | networkTimeout=10000 5 | validateDistributionUrl=true 6 | zipStoreBase=GRADLE_USER_HOME 7 | zipStorePath=wrapper/dists 8 | -------------------------------------------------------------------------------- /grpc-client-spring-boot-starter/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'java-library' 3 | } 4 | 5 | apply from: '../deploy.gradle' 6 | 7 | group = 'net.devh' 8 | version = projectVersion 9 | 10 | compileJava.dependsOn(processResources) 11 | 12 | dependencies { 13 | annotationProcessor 'org.springframework.boot:spring-boot-autoconfigure-processor' 14 | annotationProcessor 'org.springframework.boot:spring-boot-configuration-processor' 15 | 16 | api project(':grpc-common-spring-boot') 17 | api 'org.springframework.boot:spring-boot-starter' 18 | api 'jakarta.validation:jakarta.validation-api' 19 | optionalSupportImplementation "io.micrometer:micrometer-observation" 20 | optionalSupportImplementation 'org.springframework.boot:spring-boot-starter-actuator' 21 | optionalSupportImplementation 'org.springframework.cloud:spring-cloud-starter-consul-discovery' 22 | optionalSupportImplementation 'org.springframework.cloud:spring-cloud-starter-netflix-eureka-client' 23 | optionalSupportImplementation 'io.zipkin.brave:brave-instrumentation-grpc' 24 | optionalSupportImplementation 'javax.inject:javax.inject:1' 25 | // api comes from java-library, and allows exposure of the dependency to consumers of the library 26 | // this means it can be used implicitly without specifying the dependency (unless you wish to override with a different version, or exclude) 27 | optionalSupportApi 'io.grpc:grpc-netty' 28 | optionalSupportApi 'io.netty:netty-transport-native-epoll' 29 | api 'io.grpc:grpc-inprocess' 30 | api 'io.grpc:grpc-netty-shaded' 31 | api 'io.grpc:grpc-protobuf' 32 | api 'io.grpc:grpc-stub' 33 | 34 | testImplementation 'io.grpc:grpc-testing' 35 | testImplementation('org.springframework.boot:spring-boot-starter-test') 36 | } 37 | -------------------------------------------------------------------------------- /grpc-client-spring-boot-starter/src/main/java/net/devh/boot/grpc/client/autoconfigure/GrpcDiscoveryClientAutoConfiguration.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2023 The gRPC-Spring Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.devh.boot.grpc.client.autoconfigure; 18 | 19 | import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; 20 | import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; 21 | import org.springframework.cloud.client.discovery.DiscoveryClient; 22 | import org.springframework.context.annotation.Bean; 23 | import org.springframework.context.annotation.Configuration; 24 | import org.springframework.context.annotation.Lazy; 25 | 26 | import net.devh.boot.grpc.client.nameresolver.DiscoveryClientResolverFactory; 27 | 28 | @Configuration(proxyBeanMethods = false) 29 | @ConditionalOnBean(DiscoveryClient.class) 30 | public class GrpcDiscoveryClientAutoConfiguration { 31 | 32 | @ConditionalOnMissingBean 33 | @Lazy // Not needed for InProcessChannelFactories 34 | @Bean 35 | DiscoveryClientResolverFactory grpcDiscoveryClientResolverFactory(final DiscoveryClient client) { 36 | return new DiscoveryClientResolverFactory(client); 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /grpc-client-spring-boot-starter/src/main/java/net/devh/boot/grpc/client/autoconfigure/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * The Spring-Boot auto configuration classes that setup the gRPC client environment. 3 | */ 4 | 5 | package net.devh.boot.grpc.client.autoconfigure; 6 | -------------------------------------------------------------------------------- /grpc-client-spring-boot-starter/src/main/java/net/devh/boot/grpc/client/channelfactory/GrpcChannelConfigurer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2023 The gRPC-Spring Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.devh.boot.grpc.client.channelfactory; 18 | 19 | import static java.util.Objects.requireNonNull; 20 | 21 | import java.util.function.BiConsumer; 22 | 23 | import io.grpc.ManagedChannelBuilder; 24 | 25 | /** 26 | * A configurer for {@link ManagedChannelBuilder}s which can be used by {@link GrpcChannelFactory} to customize the 27 | * created channels. 28 | * 29 | * @author Daniel Theuke (daniel.theuke@heuboe.de) 30 | */ 31 | @FunctionalInterface 32 | public interface GrpcChannelConfigurer extends BiConsumer, String> { 33 | 34 | @Override 35 | default GrpcChannelConfigurer andThen(final BiConsumer, ? super String> after) { 36 | requireNonNull(after, "after"); 37 | return (l, r) -> { 38 | accept(l, r); 39 | after.accept(l, r); 40 | }; 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /grpc-client-spring-boot-starter/src/main/java/net/devh/boot/grpc/client/channelfactory/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Contains factories and related classes to setup the client's connection channels to the servers. 3 | */ 4 | 5 | package net.devh.boot.grpc.client.channelfactory; 6 | -------------------------------------------------------------------------------- /grpc-client-spring-boot-starter/src/main/java/net/devh/boot/grpc/client/config/NegotiationType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2023 The gRPC-Spring Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.devh.boot.grpc.client.config; 18 | 19 | /** 20 | * Identifies the negotiation used for starting up HTTP/2. 21 | * 22 | * @see io.grpc.netty.shaded.io.grpc.netty.NegotiationType NegotiationType 23 | */ 24 | // This class needs to be duplicated to avoid direct dependencies to either of the grpc-netty (shaded) libraries. 25 | public enum NegotiationType { 26 | 27 | /** 28 | * Uses TLS ALPN/NPN negotiation, assumes an SSL connection. 29 | */ 30 | TLS, 31 | 32 | /** 33 | * Use the HTTP UPGRADE protocol for a plaintext (non-SSL) upgrade from HTTP/1.1 to HTTP/2. 34 | */ 35 | PLAINTEXT_UPGRADE, 36 | 37 | /** 38 | * Just assume the connection is plaintext (non-SSL) and the remote endpoint supports HTTP/2 directly without an 39 | * upgrade. 40 | */ 41 | PLAINTEXT; 42 | 43 | } 44 | -------------------------------------------------------------------------------- /grpc-client-spring-boot-starter/src/main/java/net/devh/boot/grpc/client/config/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Classes related to the gRPC client configuration. 3 | */ 4 | 5 | package net.devh.boot.grpc.client.config; 6 | -------------------------------------------------------------------------------- /grpc-client-spring-boot-starter/src/main/java/net/devh/boot/grpc/client/inject/GrpcClientBeans.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2023 The gRPC-Spring Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.devh.boot.grpc.client.inject; 18 | 19 | import java.lang.annotation.ElementType; 20 | import java.lang.annotation.Retention; 21 | import java.lang.annotation.RetentionPolicy; 22 | import java.lang.annotation.Target; 23 | 24 | import org.springframework.context.ApplicationContext; 25 | import org.springframework.context.annotation.Configuration; 26 | 27 | /** 28 | * Annotation that can be added to {@link Configuration} classes to add {@link GrpcClient} beans to the 29 | * {@link ApplicationContext}. 30 | */ 31 | @Target(ElementType.TYPE) 32 | @Retention(RetentionPolicy.RUNTIME) 33 | public @interface GrpcClientBeans { 34 | 35 | /** 36 | * Helper field containing multiple {@link GrpcClientBean} definitions. 37 | * 38 | * @return An array with bean definitions to create. 39 | */ 40 | GrpcClientBean[] value(); 41 | 42 | } 43 | -------------------------------------------------------------------------------- /grpc-client-spring-boot-starter/src/main/java/net/devh/boot/grpc/client/inject/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Classes used to inject the client references into beans. 3 | */ 4 | 5 | package net.devh.boot.grpc.client.inject; 6 | -------------------------------------------------------------------------------- /grpc-client-spring-boot-starter/src/main/java/net/devh/boot/grpc/client/interceptor/GlobalClientInterceptorConfigurer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2023 The gRPC-Spring Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.devh.boot.grpc.client.interceptor; 18 | 19 | import java.util.List; 20 | 21 | import io.grpc.ClientInterceptor; 22 | 23 | /** 24 | * A bean that can be used to configure global {@link ClientInterceptor}s. 25 | * 26 | * @author Daniel Theuke (daniel.theuke@heuboe.de) 27 | */ 28 | @FunctionalInterface 29 | public interface GlobalClientInterceptorConfigurer { 30 | 31 | /** 32 | * Configures the given list of client interceptors, possibly adding new elements, removing unwanted elements, or 33 | * reordering the existing ones. 34 | * 35 | * @param interceptors A mutable list of client interceptors to configure. 36 | */ 37 | void configureClientInterceptors(List interceptors); 38 | 39 | } 40 | -------------------------------------------------------------------------------- /grpc-client-spring-boot-starter/src/main/java/net/devh/boot/grpc/client/interceptor/GrpcGlobalClientInterceptor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2023 The gRPC-Spring Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.devh.boot.grpc.client.interceptor; 18 | 19 | import java.lang.annotation.Documented; 20 | import java.lang.annotation.ElementType; 21 | import java.lang.annotation.Retention; 22 | import java.lang.annotation.RetentionPolicy; 23 | import java.lang.annotation.Target; 24 | 25 | import org.springframework.context.annotation.Bean; 26 | import org.springframework.stereotype.Component; 27 | 28 | import io.grpc.ClientInterceptor; 29 | 30 | /** 31 | * Annotation for gRPC {@link ClientInterceptor}s to apply them globally. 32 | * 33 | * @author Daniel Theuke (daniel.theuke@heuboe.de) 34 | */ 35 | @Target({ElementType.TYPE, ElementType.METHOD}) 36 | @Retention(RetentionPolicy.RUNTIME) 37 | @Documented 38 | @Component 39 | @Bean 40 | public @interface GrpcGlobalClientInterceptor { 41 | } 42 | -------------------------------------------------------------------------------- /grpc-client-spring-boot-starter/src/main/java/net/devh/boot/grpc/client/interceptor/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Classes related to the gRPC (global) client interceptors and their discovery. 3 | */ 4 | 5 | package net.devh.boot.grpc.client.interceptor; 6 | -------------------------------------------------------------------------------- /grpc-client-spring-boot-starter/src/main/java/net/devh/boot/grpc/client/metrics/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * A package containing client side classes for grpc metric collection. 3 | */ 4 | 5 | package net.devh.boot.grpc.client.metrics; 6 | -------------------------------------------------------------------------------- /grpc-client-spring-boot-starter/src/main/java/net/devh/boot/grpc/client/nameresolver/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Classes used to resolve the client name into the actual service addresses. 3 | */ 4 | 5 | package net.devh.boot.grpc.client.nameresolver; 6 | -------------------------------------------------------------------------------- /grpc-client-spring-boot-starter/src/main/java/net/devh/boot/grpc/client/security/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Contains classes and utilities that help with the user authentication. 3 | * 4 | *

5 | * It is not necessary to add Spring-Security as a 6 | * dependency in order to use this package, however, some non-trivial security setups might require it nevertheless. 7 | *

8 | */ 9 | 10 | package net.devh.boot.grpc.client.security; 11 | -------------------------------------------------------------------------------- /grpc-client-spring-boot-starter/src/main/java/net/devh/boot/grpc/client/stubfactory/AsyncStubFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2023 The gRPC-Spring Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.devh.boot.grpc.client.stubfactory; 18 | 19 | import io.grpc.stub.AbstractAsyncStub; 20 | import io.grpc.stub.AbstractStub; 21 | 22 | public class AsyncStubFactory extends StandardJavaGrpcStubFactory { 23 | 24 | @Override 25 | public boolean isApplicable(Class> stubType) { 26 | return AbstractAsyncStub.class.isAssignableFrom(stubType); 27 | } 28 | 29 | @Override 30 | protected String getFactoryMethodName() { 31 | return "newStub"; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /grpc-client-spring-boot-starter/src/main/java/net/devh/boot/grpc/client/stubfactory/BlockingStubFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2023 The gRPC-Spring Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.devh.boot.grpc.client.stubfactory; 18 | 19 | import io.grpc.stub.AbstractBlockingStub; 20 | import io.grpc.stub.AbstractStub; 21 | 22 | public class BlockingStubFactory extends StandardJavaGrpcStubFactory { 23 | 24 | @Override 25 | public boolean isApplicable(Class> stubType) { 26 | return AbstractBlockingStub.class.isAssignableFrom(stubType); 27 | } 28 | 29 | @Override 30 | protected String getFactoryMethodName() { 31 | return "newBlockingStub"; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /grpc-client-spring-boot-starter/src/main/java/net/devh/boot/grpc/client/stubfactory/FutureStubFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2023 The gRPC-Spring Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.devh.boot.grpc.client.stubfactory; 18 | 19 | import io.grpc.stub.AbstractFutureStub; 20 | import io.grpc.stub.AbstractStub; 21 | 22 | public class FutureStubFactory extends StandardJavaGrpcStubFactory { 23 | 24 | @Override 25 | public boolean isApplicable(Class> stubType) { 26 | return AbstractFutureStub.class.isAssignableFrom(stubType); 27 | } 28 | 29 | @Override 30 | protected String getFactoryMethodName() { 31 | return "newFutureStub"; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /grpc-client-spring-boot-starter/src/main/resources/META-INF/services/io.grpc.NameResolverProvider: -------------------------------------------------------------------------------- 1 | net.devh.boot.grpc.client.nameresolver.StaticNameResolverProvider -------------------------------------------------------------------------------- /grpc-client-spring-boot-starter/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports: -------------------------------------------------------------------------------- 1 | net.devh.boot.grpc.client.autoconfigure.GrpcClientAutoConfiguration 2 | net.devh.boot.grpc.client.autoconfigure.GrpcClientMetricAutoConfiguration 3 | net.devh.boot.grpc.client.autoconfigure.GrpcClientHealthAutoConfiguration 4 | net.devh.boot.grpc.client.autoconfigure.GrpcClientMicrometerTraceAutoConfiguration 5 | net.devh.boot.grpc.client.autoconfigure.GrpcClientSecurityAutoConfiguration 6 | net.devh.boot.grpc.client.autoconfigure.GrpcDiscoveryClientAutoConfiguration 7 | net.devh.boot.grpc.client.autoconfigure.GrpcClientDefaultRequestTimeoutAutoConfiguration 8 | -------------------------------------------------------------------------------- /grpc-client-spring-boot-starter/src/test/java/net/devh/boot/grpc/client/config/GrpcChannelPropertiesConfig.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2023 The gRPC-Spring Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.devh.boot.grpc.client.config; 18 | 19 | import org.springframework.boot.SpringBootConfiguration; 20 | import org.springframework.boot.context.properties.EnableConfigurationProperties; 21 | 22 | /** 23 | * Dummy config - because Spring needs one. 24 | */ 25 | @SpringBootConfiguration 26 | @EnableConfigurationProperties(GrpcChannelsProperties.class) 27 | public class GrpcChannelPropertiesConfig { 28 | } 29 | -------------------------------------------------------------------------------- /grpc-client-spring-boot-starter/src/test/java/net/devh/boot/grpc/client/config/GrpcChannelPropertiesNegativeGivenUnitTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2023 The gRPC-Spring Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.devh.boot.grpc.client.config; 18 | 19 | import static org.junit.jupiter.api.Assertions.assertEquals; 20 | 21 | import java.time.Duration; 22 | 23 | import org.junit.jupiter.api.Test; 24 | import org.junit.jupiter.api.extension.ExtendWith; 25 | import org.springframework.beans.factory.annotation.Autowired; 26 | import org.springframework.boot.test.context.SpringBootTest; 27 | import org.springframework.test.context.junit.jupiter.SpringExtension; 28 | 29 | /** 30 | * Tests whether the property resolution works with negative values and when using suffixes. 31 | */ 32 | @ExtendWith(SpringExtension.class) 33 | @SpringBootTest(properties = { 34 | "grpc.client.test.shutdownGracePeriod=-1ms" 35 | }) 36 | class GrpcChannelPropertiesNegativeGivenUnitTest { 37 | 38 | @Autowired 39 | private GrpcChannelsProperties grpcChannelsProperties; 40 | 41 | @Test 42 | void test() { 43 | final GrpcChannelProperties properties = this.grpcChannelsProperties.getChannel("test"); 44 | assertEquals(Duration.ofMillis(-1), properties.getShutdownGracePeriod()); 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /grpc-client-spring-boot-starter/src/test/java/net/devh/boot/grpc/client/config/GrpcChannelPropertiesNegativeNoUnitTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2023 The gRPC-Spring Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.devh.boot.grpc.client.config; 18 | 19 | import static org.junit.jupiter.api.Assertions.assertEquals; 20 | 21 | import java.time.Duration; 22 | 23 | import org.junit.jupiter.api.Test; 24 | import org.junit.jupiter.api.extension.ExtendWith; 25 | import org.springframework.beans.factory.annotation.Autowired; 26 | import org.springframework.boot.test.context.SpringBootTest; 27 | import org.springframework.test.context.junit.jupiter.SpringExtension; 28 | 29 | /** 30 | * Tests whether the property resolution works with negative values and without suffixes. 31 | */ 32 | @ExtendWith(SpringExtension.class) 33 | @SpringBootTest(properties = { 34 | "grpc.client.test.shutdownGracePeriod=-1" 35 | }) 36 | class GrpcChannelPropertiesNegativeNoUnitTest { 37 | 38 | @Autowired 39 | private GrpcChannelsProperties grpcChannelsProperties; 40 | 41 | @Test 42 | void test() { 43 | final GrpcChannelProperties properties = this.grpcChannelsProperties.getChannel("test"); 44 | assertEquals(Duration.ofSeconds(-1), properties.getShutdownGracePeriod()); 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /grpc-client-spring-boot-starter/src/test/java/net/devh/boot/grpc/client/metrics/FakeClock.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2023 The gRPC-Spring Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.devh.boot.grpc.client.metrics; 18 | 19 | import java.util.concurrent.TimeUnit; 20 | import java.util.function.Supplier; 21 | 22 | import com.google.common.base.Stopwatch; 23 | import com.google.common.base.Ticker; 24 | 25 | /** 26 | * A manipulated clock that exports a {@link com.google.common.base.Ticker}. 27 | */ 28 | public final class FakeClock { 29 | private long currentTimeNanos; 30 | private final Ticker ticker = 31 | new Ticker() { 32 | @Override 33 | public long read() { 34 | return currentTimeNanos; 35 | } 36 | }; 37 | 38 | private final Supplier stopwatchSupplier = () -> Stopwatch.createUnstarted(ticker); 39 | 40 | /** 41 | * Forward the time by the given duration. 42 | */ 43 | public void forwardTime(long value, TimeUnit unit) { 44 | currentTimeNanos += unit.toNanos(value); 45 | } 46 | 47 | /** 48 | * Provides a stopwatch instance that uses the fake clock ticker. 49 | */ 50 | public Supplier getStopwatchSupplier() { 51 | return stopwatchSupplier; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /grpc-client-spring-boot-starter/src/test/java/net/devh/boot/grpc/client/nameresolver/TestableListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2023 The gRPC-Spring Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.devh.boot.grpc.client.nameresolver; 18 | 19 | import io.grpc.NameResolver; 20 | import io.grpc.Status; 21 | import lombok.Getter; 22 | 23 | @Getter 24 | public class TestableListener extends NameResolver.Listener2 { 25 | 26 | private NameResolver.ResolutionResult result; 27 | private Status error; 28 | private boolean resultWasSet = false; 29 | private boolean errorWasSet = false; 30 | 31 | @Override 32 | public void onResult(NameResolver.ResolutionResult resolutionResult) { 33 | this.result = resolutionResult; 34 | resultWasSet = true; 35 | } 36 | 37 | @Override 38 | public void onError(Status error) { 39 | this.error = error; 40 | errorWasSet = true; 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /grpc-common-spring-boot/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'java-library' 3 | } 4 | 5 | apply from: '../deploy.gradle' 6 | 7 | group = 'net.devh' 8 | version = projectVersion 9 | 10 | compileJava.dependsOn(processResources) 11 | 12 | dependencies { 13 | annotationProcessor('org.springframework.boot:spring-boot-autoconfigure-processor') 14 | 15 | api('org.springframework.boot:spring-boot-starter') 16 | optionalSupportImplementation('org.springframework.boot:spring-boot-starter-actuator') 17 | api('io.grpc:grpc-core') 18 | optionalSupportImplementation('com.google.guava:guava') 19 | 20 | optionalSupportImplementation('io.zipkin.brave:brave-instrumentation-grpc') 21 | } 22 | -------------------------------------------------------------------------------- /grpc-common-spring-boot/src/main/java/net/devh/boot/grpc/common/autoconfigure/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * The Spring-Boot auto configuration classes that setup the gRPC environment with features that can be used by both the 3 | * client and the server. 4 | */ 5 | 6 | package net.devh.boot.grpc.common.autoconfigure; 7 | -------------------------------------------------------------------------------- /grpc-common-spring-boot/src/main/java/net/devh/boot/grpc/common/codec/GrpcCodec.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2023 The gRPC-Spring Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.devh.boot.grpc.common.codec; 18 | 19 | import java.lang.annotation.Documented; 20 | import java.lang.annotation.ElementType; 21 | import java.lang.annotation.Retention; 22 | import java.lang.annotation.RetentionPolicy; 23 | import java.lang.annotation.Target; 24 | 25 | import org.springframework.stereotype.Component; 26 | 27 | import io.grpc.Codec; 28 | 29 | /** 30 | * Annotation that marks gRPC codecs that should be registered with a gRPC server. This annotation should only be added 31 | * to beans that implement {@link Codec}. 32 | * 33 | * @author Michael (yidongnan@gmail.com) 34 | * @author Daniel Theuke (daniel.theuke@heuboe.de) 35 | */ 36 | @Target(ElementType.TYPE) 37 | @Retention(RetentionPolicy.RUNTIME) 38 | @Documented 39 | @Component 40 | public @interface GrpcCodec { 41 | 42 | /** 43 | * Advertised codecs will be listed in the {@code Accept-Encoding} header. Defaults to false. 44 | * 45 | * @return True, of the codec should be advertised. False otherwise. 46 | */ 47 | boolean advertised() default false; 48 | 49 | /** 50 | * Gets the type of codec the annotated bean should be used for. 51 | * 52 | * @return The type of codec. 53 | */ 54 | CodecType codecType() default CodecType.ALL; 55 | 56 | } 57 | -------------------------------------------------------------------------------- /grpc-common-spring-boot/src/main/java/net/devh/boot/grpc/common/codec/GrpcCodecDiscoverer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2023 The gRPC-Spring Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.devh.boot.grpc.common.codec; 18 | 19 | import java.util.Collection; 20 | 21 | /** 22 | * An interface for a bean that will be used to find grpc codecs. 23 | * 24 | * @author Daniel Theuke (daniel.theuke@heuboe.de) 25 | */ 26 | @FunctionalInterface 27 | public interface GrpcCodecDiscoverer { 28 | 29 | /** 30 | * Find the grpc codecs that should uses by the client/server. 31 | * 32 | * @return The grpc codecs that should be provided. Never null. 33 | */ 34 | Collection findGrpcCodecs(); 35 | 36 | } 37 | -------------------------------------------------------------------------------- /grpc-common-spring-boot/src/main/java/net/devh/boot/grpc/common/codec/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Classes related to the gRPC codec usage for both the server and the client. 3 | */ 4 | 5 | package net.devh.boot.grpc.common.codec; 6 | -------------------------------------------------------------------------------- /grpc-common-spring-boot/src/main/java/net/devh/boot/grpc/common/security/SecurityConstants.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2023 The gRPC-Spring Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.devh.boot.grpc.common.security; 18 | 19 | import java.nio.charset.StandardCharsets; 20 | 21 | import io.grpc.Metadata; 22 | import io.grpc.Metadata.Key; 23 | 24 | /** 25 | * A helper class with constants related to grpc security. 26 | * 27 | * @author Daniel Theuke (daniel.theuke@heuboe.de) 28 | */ 29 | public final class SecurityConstants { 30 | 31 | /** 32 | * A convenience constant that contains the key for the HTTP Authorization Header. 33 | */ 34 | public static final Key AUTHORIZATION_HEADER = Key.of("Authorization", Metadata.ASCII_STRING_MARSHALLER); 35 | 36 | /** 37 | * The prefix for basic auth as used in the {@link #AUTHORIZATION_HEADER}. This library assumes that the both the 38 | * username and password are {@link StandardCharsets#UTF_8 UTF_8} encoded before being turned into a base64 string. 39 | */ 40 | public static final String BASIC_AUTH_PREFIX = "Basic "; 41 | 42 | /** 43 | * The prefix for bearer auth as used in the {@link #AUTHORIZATION_HEADER}. 44 | */ 45 | public static final String BEARER_AUTH_PREFIX = "Bearer "; 46 | 47 | private SecurityConstants() {} 48 | 49 | } 50 | -------------------------------------------------------------------------------- /grpc-common-spring-boot/src/main/java/net/devh/boot/grpc/common/security/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Contains classes and utilities that related to security that are used by both the client and the server. 3 | */ 4 | 5 | package net.devh.boot.grpc.common.security; 6 | -------------------------------------------------------------------------------- /grpc-common-spring-boot/src/main/java/net/devh/boot/grpc/common/util/Constants.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2023 The gRPC-Spring Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.devh.boot.grpc.common.util; 18 | 19 | /** 20 | * Class that contains shared constants. 21 | */ 22 | public final class Constants { 23 | 24 | /** 25 | * A constant that defines the current version of the library. 26 | */ 27 | public static final String VERSION = "v" + Constants.class.getPackage().getImplementationVersion(); 28 | 29 | /** 30 | * A constant that defines the library name that can be used as metric tags. 31 | */ 32 | public static final String LIBRARY_NAME = "grpc-spring"; 33 | 34 | private Constants() {} 35 | 36 | } 37 | -------------------------------------------------------------------------------- /grpc-common-spring-boot/src/main/java/net/devh/boot/grpc/common/util/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Utilities for both the server and the client. 3 | */ 4 | 5 | package net.devh.boot.grpc.common.util; 6 | -------------------------------------------------------------------------------- /grpc-common-spring-boot/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports: -------------------------------------------------------------------------------- 1 | net.devh.boot.grpc.common.autoconfigure.GrpcCommonCodecAutoConfiguration 2 | -------------------------------------------------------------------------------- /grpc-server-spring-boot-starter/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'java-library' 3 | } 4 | 5 | apply from: '../deploy.gradle' 6 | 7 | group = 'net.devh' 8 | version = projectVersion 9 | 10 | compileJava.dependsOn(processResources) 11 | 12 | dependencies { 13 | annotationProcessor 'org.springframework.boot:spring-boot-autoconfigure-processor' 14 | annotationProcessor 'org.springframework.boot:spring-boot-configuration-processor' 15 | 16 | api project(':grpc-common-spring-boot') 17 | api 'org.springframework.boot:spring-boot-starter' 18 | optionalSupportImplementation "io.micrometer:micrometer-observation" 19 | optionalSupportImplementation 'org.springframework.boot:spring-boot-starter-actuator' 20 | optionalSupportImplementation 'org.springframework.security:spring-security-core' 21 | optionalSupportImplementation 'org.springframework.cloud:spring-cloud-starter-consul-discovery' 22 | optionalSupportImplementation 'org.springframework.cloud:spring-cloud-starter-zookeeper-discovery' 23 | optionalSupportImplementation 'org.springframework.cloud:spring-cloud-starter-netflix-eureka-client' 24 | optionalSupportImplementation "com.alibaba.cloud:spring-cloud-starter-alibaba-nacos-discovery" 25 | optionalSupportImplementation 'io.zipkin.brave:brave-instrumentation-grpc' 26 | optionalSupportApi 'io.grpc:grpc-netty' 27 | api 'io.grpc:grpc-inprocess' 28 | api 'io.grpc:grpc-netty-shaded' 29 | api 'io.grpc:grpc-protobuf' 30 | api 'io.grpc:grpc-stub' 31 | api 'io.grpc:grpc-services' 32 | api 'io.grpc:grpc-api' 33 | 34 | testImplementation 'io.grpc:grpc-testing' 35 | testImplementation('org.springframework.boot:spring-boot-starter-test') 36 | } 37 | -------------------------------------------------------------------------------- /grpc-server-spring-boot-starter/src/main/java/net/devh/boot/grpc/server/advice/GrpcAdvice.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2023 The gRPC-Spring Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.devh.boot.grpc.server.advice; 18 | 19 | import java.lang.annotation.Documented; 20 | import java.lang.annotation.ElementType; 21 | import java.lang.annotation.Retention; 22 | import java.lang.annotation.RetentionPolicy; 23 | import java.lang.annotation.Target; 24 | 25 | import org.springframework.stereotype.Component; 26 | 27 | /** 28 | * Special {@link Component @Component} to declare global gRPC exception handling. 29 | * 30 | *

31 | * Every class annotated with {@link GrpcAdvice @GrpcAdvice} is marked to be scanned for 32 | * {@link GrpcExceptionHandler @GrpcExceptionHandler} annotations. 33 | *

34 | * 35 | * @author Andjelko Perisic (andjelko.perisic@gmail.com) 36 | * @see GrpcExceptionHandler 37 | */ 38 | @Target({ElementType.TYPE, ElementType.METHOD}) 39 | @Retention(RetentionPolicy.RUNTIME) 40 | @Documented 41 | @Component 42 | public @interface GrpcAdvice { 43 | 44 | } 45 | -------------------------------------------------------------------------------- /grpc-server-spring-boot-starter/src/main/java/net/devh/boot/grpc/server/autoconfigure/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * The Spring-Boot auto configuration classes that setup the gRPC server environment. 3 | */ 4 | 5 | package net.devh.boot.grpc.server.autoconfigure; 6 | -------------------------------------------------------------------------------- /grpc-server-spring-boot-starter/src/main/java/net/devh/boot/grpc/server/condition/ConditionalOnInterprocessServer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2023 The gRPC-Spring Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.devh.boot.grpc.server.condition; 18 | 19 | import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; 20 | import org.springframework.boot.autoconfigure.condition.NoneNestedConditions; 21 | 22 | /** 23 | * A condition that matches if the {@code grpc.server.port} does not have the value {@code -1}. 24 | * 25 | * @author Daniel Theuke (daniel.theuke@heuboe.de) 26 | */ 27 | public class ConditionalOnInterprocessServer extends NoneNestedConditions { 28 | 29 | ConditionalOnInterprocessServer() { 30 | super(ConfigurationPhase.REGISTER_BEAN); 31 | } 32 | 33 | @ConditionalOnProperty(name = "grpc.server.port", havingValue = "-1") 34 | static class NoServerPortCondition { 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /grpc-server-spring-boot-starter/src/main/java/net/devh/boot/grpc/server/config/ClientAuth.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2023 The gRPC-Spring Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.devh.boot.grpc.server.config; 18 | 19 | import javax.net.ssl.SSLEngine; 20 | 21 | /** 22 | * Indicates the state of the {@link SSLEngine} with respect to client authentication. This configuration item really 23 | * only applies when building the server-side SslContext. 24 | */ 25 | public enum ClientAuth { 26 | 27 | /** 28 | * Indicates that the {@link SSLEngine} will not request client authentication. 29 | */ 30 | NONE, 31 | 32 | /** 33 | * Indicates that the {@link SSLEngine} will request client authentication. 34 | */ 35 | OPTIONAL, 36 | 37 | /** 38 | * Indicates that the {@link SSLEngine} will require client authentication. 39 | */ 40 | REQUIRE; 41 | 42 | } 43 | -------------------------------------------------------------------------------- /grpc-server-spring-boot-starter/src/main/java/net/devh/boot/grpc/server/config/HealthOptions.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2024 The gRPC-Spring Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.devh.boot.grpc.server.config; 18 | 19 | import lombok.Data; 20 | 21 | /** 22 | * GRPC Health service options. 23 | */ 24 | @Data 25 | public class HealthOptions { 26 | 27 | /** 28 | * Implementation of gRPC health service. Defaults to {@link HealthType#GRPC GRPC}. To disable health service set to 29 | * {@link HealthType#NONE NONE}. 30 | * 31 | * @see net.devh.boot.grpc.server.autoconfigure.GrpcHealthServiceAutoConfiguration 32 | * @param type The implementation of gRPC health service. 33 | * @return GRPC, ACTUATOR or NONE. 34 | */ 35 | private HealthType type = HealthType.GRPC; 36 | } 37 | -------------------------------------------------------------------------------- /grpc-server-spring-boot-starter/src/main/java/net/devh/boot/grpc/server/config/HealthType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2024 The gRPC-Spring Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.devh.boot.grpc.server.config; 18 | 19 | 20 | /** 21 | * Enum to specify the type of health service to use in GRPC. 22 | */ 23 | public enum HealthType { 24 | /** 25 | * Use the standard GRPC health service from io.grpc. 26 | * 27 | * @see net.devh.boot.grpc.server.autoconfigure.GrpcHealthServiceAutoConfiguration#grpcHealthService 28 | */ 29 | GRPC, 30 | /** 31 | * Uses a bridge to the Spring Boot Actuator health service. 32 | * 33 | * @see net.devh.boot.grpc.server.autoconfigure.GrpcHealthServiceAutoConfiguration#grpcHealthServiceActuator 34 | * @see net.devh.boot.grpc.server.health.ActuatorGrpcHealth 35 | */ 36 | ACTUATOR, 37 | /** 38 | * No health service will be created. 39 | */ 40 | NONE 41 | } 42 | -------------------------------------------------------------------------------- /grpc-server-spring-boot-starter/src/main/java/net/devh/boot/grpc/server/config/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Classes related to the gRPC server configuration. 3 | */ 4 | 5 | package net.devh.boot.grpc.server.config; 6 | -------------------------------------------------------------------------------- /grpc-server-spring-boot-starter/src/main/java/net/devh/boot/grpc/server/error/GrpcExceptionResponseHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2023 The gRPC-Spring Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.devh.boot.grpc.server.error; 18 | 19 | import io.grpc.Metadata; 20 | import io.grpc.ServerCall; 21 | import io.grpc.Status; 22 | import io.grpc.stub.StreamObserver; 23 | 24 | /** 25 | * An exception handler for errors in the grpc call execution (For both the grpc method implementations and the 26 | * {@link StreamObserver}s used to process incoming messages and sending outgoing errors). 27 | * 28 | *

29 | * Implementations must: 30 | *

31 | * 32 | *
    33 | *
  • Call {@link ServerCall#close(Status, Metadata)} before returning
  • 34 | *
  • Not throw (any thrown errors must be caught)
  • 35 | *
  • Not keep a reference to the call instance after the call
  • 36 | *
37 | */ 38 | public interface GrpcExceptionResponseHandler { 39 | 40 | /** 41 | * Handles an exception by closing the call with an appropriate {@link Status}. 42 | * 43 | * @param serverCall The server call used to send the response status. 44 | * @param error The error to handle. 45 | */ 46 | void handleError(final ServerCall serverCall, final Throwable error); 47 | 48 | } 49 | -------------------------------------------------------------------------------- /grpc-server-spring-boot-starter/src/main/java/net/devh/boot/grpc/server/event/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Grpc server events. 3 | */ 4 | 5 | package net.devh.boot.grpc.server.event; 6 | -------------------------------------------------------------------------------- /grpc-server-spring-boot-starter/src/main/java/net/devh/boot/grpc/server/interceptor/GlobalServerInterceptorConfigurer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2023 The gRPC-Spring Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.devh.boot.grpc.server.interceptor; 18 | 19 | import java.util.List; 20 | 21 | import io.grpc.ServerInterceptor; 22 | 23 | /** 24 | * A bean that can be used to configure global {@link ServerInterceptor}s. 25 | * 26 | * @author Daniel Theuke (daniel.theuke@heuboe.de) 27 | */ 28 | @FunctionalInterface 29 | public interface GlobalServerInterceptorConfigurer { 30 | 31 | /** 32 | * Configures the given list of server interceptors, possibly adding new elements, removing unwanted elements, or 33 | * reordering the existing ones. 34 | * 35 | * @param interceptors A mutable list of server interceptors to configure. 36 | */ 37 | void configureServerInterceptors(List interceptors); 38 | 39 | } 40 | -------------------------------------------------------------------------------- /grpc-server-spring-boot-starter/src/main/java/net/devh/boot/grpc/server/interceptor/GrpcGlobalServerInterceptor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2023 The gRPC-Spring Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.devh.boot.grpc.server.interceptor; 18 | 19 | import java.lang.annotation.Documented; 20 | import java.lang.annotation.ElementType; 21 | import java.lang.annotation.Retention; 22 | import java.lang.annotation.RetentionPolicy; 23 | import java.lang.annotation.Target; 24 | 25 | import org.springframework.context.annotation.Bean; 26 | import org.springframework.stereotype.Component; 27 | 28 | import io.grpc.ServerInterceptor; 29 | 30 | /** 31 | * Annotation for gRPC {@link ServerInterceptor}s to apply them globally. 32 | * 33 | * @author Daniel Theuke (daniel.theuke@heuboe.de) 34 | */ 35 | @Target({ElementType.TYPE, ElementType.METHOD}) 36 | @Retention(RetentionPolicy.RUNTIME) 37 | @Documented 38 | @Component 39 | @Bean 40 | public @interface GrpcGlobalServerInterceptor { 41 | } 42 | -------------------------------------------------------------------------------- /grpc-server-spring-boot-starter/src/main/java/net/devh/boot/grpc/server/interceptor/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Classes related to the gRPC (global) server interceptors and their discovery. 3 | */ 4 | 5 | package net.devh.boot.grpc.server.interceptor; 6 | -------------------------------------------------------------------------------- /grpc-server-spring-boot-starter/src/main/java/net/devh/boot/grpc/server/nameresolver/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Classes used to resolve the client name into the actual service addresses. 3 | */ 4 | 5 | package net.devh.boot.grpc.server.nameresolver; 6 | -------------------------------------------------------------------------------- /grpc-server-spring-boot-starter/src/main/java/net/devh/boot/grpc/server/security/authentication/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Contains the security classes related to authentication checks. 3 | */ 4 | 5 | package net.devh.boot.grpc.server.security.authentication; 6 | -------------------------------------------------------------------------------- /grpc-server-spring-boot-starter/src/main/java/net/devh/boot/grpc/server/security/check/AbstractGrpcSecurityMetadataSource.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2023 The gRPC-Spring Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.devh.boot.grpc.server.security.check; 18 | 19 | import java.util.Collection; 20 | 21 | import org.springframework.security.access.ConfigAttribute; 22 | 23 | import io.grpc.ServerCall; 24 | 25 | /** 26 | * Abstract implementation of {@link GrpcSecurityMetadataSource} which resolves the secured object type to a 27 | * {@link ServerCall}. 28 | * 29 | * @author Daniel Theuke (daniel.theuke@aequitas-software.de) 30 | */ 31 | public abstract class AbstractGrpcSecurityMetadataSource implements GrpcSecurityMetadataSource { 32 | 33 | @Override 34 | public final Collection getAttributes(final Object object) throws IllegalArgumentException { 35 | if (object instanceof ServerCall) { 36 | return getAttributes((ServerCall) object); 37 | } 38 | throw new IllegalArgumentException("Object must be a ServerCall"); 39 | } 40 | 41 | @Override 42 | public final boolean supports(final Class clazz) { 43 | return ServerCall.class.isAssignableFrom(clazz); 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /grpc-server-spring-boot-starter/src/main/java/net/devh/boot/grpc/server/security/check/GrpcSecurityMetadataSource.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2023 The gRPC-Spring Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.devh.boot.grpc.server.security.check; 18 | 19 | import java.util.Collection; 20 | 21 | import org.springframework.security.access.AccessDecisionVoter; 22 | import org.springframework.security.access.ConfigAttribute; 23 | import org.springframework.security.access.SecurityMetadataSource; 24 | 25 | import io.grpc.ServerCall; 26 | 27 | /** 28 | * A {@link SecurityMetadataSource} for grpc requests. 29 | * 30 | *

31 | * Note: The authorization checking via this metadata source will only be enabled, if both an 32 | * {@link AccessDecisionVoter} and a {@link GrpcSecurityMetadataSource} are present in the application context. 33 | *

34 | * 35 | * @author Daniel Theuke (daniel.theuke@aequitas-software.de) 36 | */ 37 | public interface GrpcSecurityMetadataSource extends SecurityMetadataSource { 38 | 39 | /** 40 | * Accesses the {@code ConfigAttribute}s that apply to a given secure object. 41 | * 42 | * @param call The grpc call being secured. 43 | * @return The attributes that apply to the passed in secured object. Should return an empty collection if there are 44 | * no applicable attributes. 45 | */ 46 | Collection getAttributes(final ServerCall call); 47 | 48 | } 49 | -------------------------------------------------------------------------------- /grpc-server-spring-boot-starter/src/main/java/net/devh/boot/grpc/server/security/check/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Contains the security classes related to authorization checks. 3 | */ 4 | 5 | package net.devh.boot.grpc.server.security.check; 6 | -------------------------------------------------------------------------------- /grpc-server-spring-boot-starter/src/main/java/net/devh/boot/grpc/server/security/interceptors/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Contains the interceptors that handle the security for the actual gRPC requests. 3 | */ 4 | 5 | package net.devh.boot.grpc.server.security.interceptors; 6 | -------------------------------------------------------------------------------- /grpc-server-spring-boot-starter/src/main/java/net/devh/boot/grpc/server/security/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Contains classes that check the user's authentication and authorization. 3 | * 4 | *

5 | * Requires Spring-Security. You might need additional 6 | * libraries, if you want to use additional features such as OAuth or other authentication schemes. 7 | *

8 | */ 9 | 10 | package net.devh.boot.grpc.server.security; 11 | -------------------------------------------------------------------------------- /grpc-server-spring-boot-starter/src/main/java/net/devh/boot/grpc/server/serverfactory/GrpcServerConfigurer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2023 The gRPC-Spring Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.devh.boot.grpc.server.serverfactory; 18 | 19 | import java.util.Objects; 20 | import java.util.function.Consumer; 21 | 22 | import io.grpc.ServerBuilder; 23 | 24 | /** 25 | * A configurer for {@link ServerBuilder}s which can be used by {@link GrpcServerFactory} to customize the created 26 | * server. 27 | * 28 | * @author Daniel Theuke (daniel.theuke@heuboe.de) 29 | */ 30 | @FunctionalInterface 31 | public interface GrpcServerConfigurer extends Consumer> { 32 | 33 | @Override 34 | default GrpcServerConfigurer andThen(final Consumer> after) { 35 | Objects.requireNonNull(after); 36 | return t -> { 37 | accept(t); 38 | after.accept(t); 39 | }; 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /grpc-server-spring-boot-starter/src/main/java/net/devh/boot/grpc/server/serverfactory/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Contains factories and related classes to setup the server. 3 | */ 4 | 5 | package net.devh.boot.grpc.server.serverfactory; 6 | -------------------------------------------------------------------------------- /grpc-server-spring-boot-starter/src/main/java/net/devh/boot/grpc/server/service/GrpcServiceDiscoverer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2023 The gRPC-Spring Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.devh.boot.grpc.server.service; 18 | 19 | import java.util.Collection; 20 | 21 | import net.devh.boot.grpc.server.serverfactory.GrpcServerFactory; 22 | 23 | /** 24 | * An interface for a bean that will be used to find grpc services and codecs. These will then be provided to the 25 | * {@link GrpcServerFactory} which then uses them to configure the server. 26 | * 27 | * @author Michael (yidongnan@gmail.com) 28 | * @since 5/17/16 29 | */ 30 | @FunctionalInterface 31 | public interface GrpcServiceDiscoverer { 32 | 33 | /** 34 | * Find the grpc services that should provided by the server. 35 | * 36 | * @return The grpc services that should be provided. Never null. 37 | */ 38 | Collection findGrpcServices(); 39 | 40 | } 41 | -------------------------------------------------------------------------------- /grpc-server-spring-boot-starter/src/main/java/net/devh/boot/grpc/server/service/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Classes related to the gRPC server services and their discovery. 3 | */ 4 | 5 | package net.devh.boot.grpc.server.service; 6 | -------------------------------------------------------------------------------- /grpc-server-spring-boot-starter/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports: -------------------------------------------------------------------------------- 1 | net.devh.boot.grpc.server.autoconfigure.GrpcAdviceAutoConfiguration 2 | net.devh.boot.grpc.server.autoconfigure.GrpcHealthServiceAutoConfiguration 3 | net.devh.boot.grpc.server.autoconfigure.GrpcMetadataConsulConfiguration 4 | net.devh.boot.grpc.server.autoconfigure.GrpcMetadataEurekaConfiguration 5 | net.devh.boot.grpc.server.autoconfigure.GrpcMetadataNacosConfiguration 6 | net.devh.boot.grpc.server.autoconfigure.GrpcMetadataZookeeperConfiguration 7 | net.devh.boot.grpc.server.autoconfigure.GrpcReflectionServiceAutoConfiguration 8 | net.devh.boot.grpc.server.autoconfigure.GrpcServerAutoConfiguration 9 | net.devh.boot.grpc.server.autoconfigure.GrpcServerFactoryAutoConfiguration 10 | net.devh.boot.grpc.server.autoconfigure.GrpcServerMetricAutoConfiguration 11 | net.devh.boot.grpc.server.autoconfigure.GrpcServerMicrometerTraceAutoConfiguration 12 | net.devh.boot.grpc.server.autoconfigure.GrpcServerSecurityAutoConfiguration 13 | -------------------------------------------------------------------------------- /grpc-server-spring-boot-starter/src/test/java/net/devh/boot/grpc/server/autoconfigure/GrpcHealthServiceTrueAutoConfigurationTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2023 The gRPC-Spring Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.devh.boot.grpc.server.autoconfigure; 18 | 19 | import org.springframework.boot.autoconfigure.ImportAutoConfiguration; 20 | import org.springframework.boot.test.context.SpringBootTest; 21 | import org.springframework.test.annotation.DirtiesContext; 22 | 23 | @SpringBootTest(classes = GrpcHealthServiceDefaultAutoConfigurationTest.TestConfig.class, 24 | properties = "grpc.server.health-service.type=GRPC") 25 | @ImportAutoConfiguration({ 26 | GrpcServerAutoConfiguration.class, 27 | GrpcServerFactoryAutoConfiguration.class, 28 | GrpcHealthServiceAutoConfiguration.class}) 29 | @DirtiesContext 30 | class GrpcHealthServiceTrueAutoConfigurationTest extends GrpcHealthServiceDefaultAutoConfigurationTest { 31 | } 32 | -------------------------------------------------------------------------------- /grpc-server-spring-boot-starter/src/test/java/net/devh/boot/grpc/server/autoconfigure/GrpcReflectionServiceTrueAutoConfigurationTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2023 The gRPC-Spring Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.devh.boot.grpc.server.autoconfigure; 18 | 19 | import org.springframework.boot.autoconfigure.ImportAutoConfiguration; 20 | import org.springframework.boot.test.context.SpringBootTest; 21 | import org.springframework.test.annotation.DirtiesContext; 22 | 23 | @SpringBootTest(classes = GrpcReflectionServiceDefaultAutoConfigurationTest.TestConfig.class, 24 | properties = "grpc.server.reflection-service-enabled=true") 25 | @ImportAutoConfiguration({ 26 | GrpcServerAutoConfiguration.class, 27 | GrpcServerFactoryAutoConfiguration.class, 28 | GrpcReflectionServiceAutoConfiguration.class}) 29 | @DirtiesContext 30 | class GrpcReflectionServiceTrueAutoConfigurationTest extends GrpcReflectionServiceDefaultAutoConfigurationTest { 31 | } 32 | -------------------------------------------------------------------------------- /grpc-server-spring-boot-starter/src/test/java/net/devh/boot/grpc/server/config/GrpcServerPropertiesConfig.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2023 The gRPC-Spring Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.devh.boot.grpc.server.config; 18 | 19 | import org.springframework.boot.SpringBootConfiguration; 20 | import org.springframework.boot.context.properties.EnableConfigurationProperties; 21 | 22 | /** 23 | * Dummy config - because Spring needs one. 24 | */ 25 | @SpringBootConfiguration 26 | @EnableConfigurationProperties(GrpcServerProperties.class) 27 | public class GrpcServerPropertiesConfig { 28 | } 29 | -------------------------------------------------------------------------------- /grpc-server-spring-boot-starter/src/test/java/net/devh/boot/grpc/server/config/GrpcServerPropertiesNegativeGivenUnitTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2023 The gRPC-Spring Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.devh.boot.grpc.server.config; 18 | 19 | import static org.junit.jupiter.api.Assertions.assertEquals; 20 | 21 | import java.time.Duration; 22 | 23 | import org.junit.jupiter.api.Test; 24 | import org.junit.jupiter.api.extension.ExtendWith; 25 | import org.springframework.beans.factory.annotation.Autowired; 26 | import org.springframework.boot.test.context.SpringBootTest; 27 | import org.springframework.test.context.junit.jupiter.SpringExtension; 28 | 29 | /** 30 | * Tests whether the property resolution works with negative values and suffixes. 31 | */ 32 | @ExtendWith(SpringExtension.class) 33 | @SpringBootTest(properties = { 34 | "grpc.server.shutdownGracePeriod=-1ms" 35 | }) 36 | class GrpcServerPropertiesNegativeGivenUnitTest { 37 | 38 | @Autowired 39 | private GrpcServerProperties grpcServerProperties; 40 | 41 | @Test 42 | void test() { 43 | assertEquals(Duration.ofMillis(-1), this.grpcServerProperties.getShutdownGracePeriod()); 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /grpc-server-spring-boot-starter/src/test/java/net/devh/boot/grpc/server/config/GrpcServerPropertiesNegativeNoUnitTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2023 The gRPC-Spring Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.devh.boot.grpc.server.config; 18 | 19 | import static org.junit.jupiter.api.Assertions.assertEquals; 20 | 21 | import java.time.Duration; 22 | 23 | import org.junit.jupiter.api.Test; 24 | import org.junit.jupiter.api.extension.ExtendWith; 25 | import org.springframework.beans.factory.annotation.Autowired; 26 | import org.springframework.boot.test.context.SpringBootTest; 27 | import org.springframework.test.context.junit.jupiter.SpringExtension; 28 | 29 | /** 30 | * Tests whether the property resolution works with negative values and without suffixes. 31 | */ 32 | @ExtendWith(SpringExtension.class) 33 | @SpringBootTest(properties = { 34 | "grpc.server.shutdownGracePeriod=-1" 35 | }) 36 | class GrpcServerPropertiesNegativeNoUnitTest { 37 | 38 | @Autowired 39 | private GrpcServerProperties grpcServerProperties; 40 | 41 | @Test 42 | void test() { 43 | assertEquals(Duration.ofSeconds(-1), this.grpcServerProperties.getShutdownGracePeriod()); 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /grpc-server-spring-boot-starter/src/test/java/net/devh/boot/grpc/server/config/GrpcServerPropertiesNoUnitTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2023 The gRPC-Spring Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.devh.boot.grpc.server.config; 18 | 19 | import static org.junit.jupiter.api.Assertions.assertEquals; 20 | 21 | import java.time.Duration; 22 | 23 | import org.junit.jupiter.api.Test; 24 | import org.junit.jupiter.api.extension.ExtendWith; 25 | import org.springframework.beans.factory.annotation.Autowired; 26 | import org.springframework.boot.test.context.SpringBootTest; 27 | import org.springframework.test.context.junit.jupiter.SpringExtension; 28 | import org.springframework.util.unit.DataSize; 29 | 30 | /** 31 | * Tests whether the property resolution works without suffixes (backwards compatibility). 32 | */ 33 | @ExtendWith(SpringExtension.class) 34 | @SpringBootTest(properties = { 35 | "grpc.server.keepAliveTime=42", 36 | "grpc.server.maxInboundMessageSize=5242880" 37 | }) 38 | class GrpcServerPropertiesNoUnitTest { 39 | 40 | @Autowired 41 | private GrpcServerProperties grpcServerProperties; 42 | 43 | @Test 44 | void test() { 45 | assertEquals(Duration.ofSeconds(42), this.grpcServerProperties.getKeepAliveTime()); 46 | assertEquals(DataSize.ofMegabytes(5), this.grpcServerProperties.getMaxInboundMessageSize()); 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /grpc-server-spring-boot-starter/src/test/java/net/devh/boot/grpc/server/metrics/FakeClock.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2023 The gRPC-Spring Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.devh.boot.grpc.server.metrics; 18 | 19 | import java.util.concurrent.TimeUnit; 20 | import java.util.function.Supplier; 21 | 22 | import com.google.common.base.Stopwatch; 23 | import com.google.common.base.Ticker; 24 | 25 | /** 26 | * A manipulated clock that exports a {@link com.google.common.base.Ticker}. 27 | */ 28 | public final class FakeClock { 29 | private long currentTimeNanos; 30 | private final Ticker ticker = 31 | new Ticker() { 32 | @Override 33 | public long read() { 34 | return currentTimeNanos; 35 | } 36 | }; 37 | 38 | private final Supplier stopwatchSupplier = () -> Stopwatch.createUnstarted(ticker); 39 | 40 | /** 41 | * Forward the time by the given duration. 42 | */ 43 | public void forwardTime(long value, TimeUnit unit) { 44 | currentTimeNanos += unit.toNanos(value); 45 | } 46 | 47 | /** 48 | * Provides a stopwatch instance that uses the fake clock ticker. 49 | */ 50 | public Supplier getStopwatchSupplier() { 51 | return stopwatchSupplier; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /grpc-server-spring-boot-starter/src/test/resources/logback-test.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | %highlight(%d{HH:mm:ss.SSS} [%10thread] %-5level %logger{36} - %msg%n) 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /private.key.enc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/grpc-ecosystem/grpc-spring/b83afe68cef63edc7dfeec694bc279956bbc8c3d/private.key.enc -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'grpc-spring-boot-starter' 2 | 3 | include "grpc-common-spring-boot" 4 | include "grpc-client-spring-boot-starter" 5 | include "grpc-server-spring-boot-starter" 6 | 7 | include "tests" 8 | 9 | // examples 10 | include "examples:grpc-lib" 11 | include "examples:local-grpc-client" 12 | include "examples:local-grpc-server" 13 | include "examples:cloud-eureka-server" 14 | include "examples:cloud-grpc-client" 15 | include "examples:cloud-grpc-server" 16 | include "examples:security-grpc-client" 17 | include "examples:security-grpc-server" 18 | include "examples:grpc-observability:backend" 19 | include "examples:grpc-observability:frontend" 20 | include "examples:grpc-observability:proto" 21 | -------------------------------------------------------------------------------- /tests/src/test/java/net/devh/boot/grpc/test/advice/GrpcMetaDataUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2023 The gRPC-Spring Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.devh.boot.grpc.test.advice; 18 | 19 | import io.grpc.Metadata; 20 | 21 | public class GrpcMetaDataUtils { 22 | 23 | private GrpcMetaDataUtils() { 24 | throw new UnsupportedOperationException("Util class not to be instantiated."); 25 | } 26 | 27 | public static Metadata createExpectedAsciiHeader() { 28 | 29 | return createAsciiHeader("HEADER_KEY", "HEADER_VALUE"); 30 | } 31 | 32 | 33 | public static Metadata createAsciiHeader(String key, String value) { 34 | 35 | Metadata metadata = new Metadata(); 36 | Metadata.Key asciiKey = Metadata.Key.of(key, Metadata.ASCII_STRING_MARSHALLER); 37 | metadata.put(asciiKey, value); 38 | return metadata; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /tests/src/test/java/net/devh/boot/grpc/test/config/AnnotatedSecurityConfiguration.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2023 The gRPC-Spring Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.devh.boot.grpc.test.config; 18 | 19 | import org.springframework.context.annotation.Configuration; 20 | import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity; 21 | 22 | @Configuration 23 | // proxyTargetClass is required, if you use annotation driven security! 24 | // However, you will receive a warning that TestServiceImpl#bindService() method is final. 25 | // You cannot avoid that warning (without massive amount of work), but it is safe to ignore it. 26 | // The #bindService() method uses a reference to 'this', which will be used to invoke the methods. 27 | // If the method is not final it will delegate to the original instance and thus it will bypass any security layer that 28 | // you intend to add, unless you re-implement the #bindService() method on the outermost layer (which Spring does not). 29 | @EnableGlobalMethodSecurity(securedEnabled = true, proxyTargetClass = true) 30 | public class AnnotatedSecurityConfiguration { 31 | } 32 | -------------------------------------------------------------------------------- /tests/src/test/java/net/devh/boot/grpc/test/config/BaseAutoConfiguration.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2023 The gRPC-Spring Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.devh.boot.grpc.test.config; 18 | 19 | import org.springframework.boot.autoconfigure.ImportAutoConfiguration; 20 | import org.springframework.context.annotation.Configuration; 21 | 22 | import net.devh.boot.grpc.client.autoconfigure.GrpcClientAutoConfiguration; 23 | import net.devh.boot.grpc.client.autoconfigure.GrpcClientDefaultRequestTimeoutAutoConfiguration; 24 | import net.devh.boot.grpc.common.autoconfigure.GrpcCommonCodecAutoConfiguration; 25 | import net.devh.boot.grpc.server.autoconfigure.GrpcServerAutoConfiguration; 26 | import net.devh.boot.grpc.server.autoconfigure.GrpcServerFactoryAutoConfiguration; 27 | import net.devh.boot.grpc.server.autoconfigure.GrpcServerSecurityAutoConfiguration; 28 | 29 | @Configuration 30 | @ImportAutoConfiguration({GrpcCommonCodecAutoConfiguration.class, GrpcServerAutoConfiguration.class, 31 | GrpcServerFactoryAutoConfiguration.class, GrpcServerSecurityAutoConfiguration.class, 32 | GrpcClientAutoConfiguration.class, GrpcClientDefaultRequestTimeoutAutoConfiguration.class}) 33 | public class BaseAutoConfiguration { 34 | 35 | } 36 | -------------------------------------------------------------------------------- /tests/src/test/java/net/devh/boot/grpc/test/config/MetricConfiguration.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2023 The gRPC-Spring Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.devh.boot.grpc.test.config; 18 | 19 | import org.springframework.boot.autoconfigure.ImportAutoConfiguration; 20 | import org.springframework.context.annotation.Bean; 21 | import org.springframework.context.annotation.Configuration; 22 | 23 | import io.micrometer.core.instrument.MeterRegistry; 24 | import io.micrometer.core.instrument.simple.SimpleMeterRegistry; 25 | import net.devh.boot.grpc.client.autoconfigure.GrpcClientMetricAutoConfiguration; 26 | import net.devh.boot.grpc.server.autoconfigure.GrpcServerMetricAutoConfiguration; 27 | 28 | @Configuration 29 | @ImportAutoConfiguration({GrpcClientMetricAutoConfiguration.class, GrpcServerMetricAutoConfiguration.class}) 30 | public class MetricConfiguration { 31 | 32 | @Bean 33 | MeterRegistry meterRegistry() { 34 | return new SimpleMeterRegistry(); 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /tests/src/test/java/net/devh/boot/grpc/test/config/ScopedServiceConfiguration.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2023 The gRPC-Spring Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.devh.boot.grpc.test.config; 18 | 19 | import org.springframework.context.annotation.Bean; 20 | import org.springframework.context.annotation.Configuration; 21 | import org.springframework.context.annotation.Scope; 22 | import org.springframework.context.annotation.ScopedProxyMode; 23 | 24 | import net.devh.boot.grpc.server.scope.GrpcRequestScope; 25 | import net.devh.boot.grpc.test.server.ScopedTestServiceImpl; 26 | import net.devh.boot.grpc.test.server.ScopedTestServiceImpl.RequestId; 27 | import net.devh.boot.grpc.test.server.TestServiceImpl; 28 | 29 | @Configuration 30 | public class ScopedServiceConfiguration extends ServiceConfiguration { 31 | 32 | @Override 33 | @Bean 34 | TestServiceImpl testService() { 35 | return new ScopedTestServiceImpl(); 36 | } 37 | 38 | @Bean 39 | @Scope(scopeName = GrpcRequestScope.GRPC_REQUEST_SCOPE_NAME, proxyMode = ScopedProxyMode.TARGET_CLASS) 40 | RequestId requestId() { 41 | return new RequestId(); 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /tests/src/test/java/net/devh/boot/grpc/test/config/ServiceConfiguration.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2023 The gRPC-Spring Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.devh.boot.grpc.test.config; 18 | 19 | import org.springframework.context.annotation.Bean; 20 | import org.springframework.context.annotation.Configuration; 21 | 22 | import net.devh.boot.grpc.test.server.TestServiceImpl; 23 | 24 | @Configuration 25 | public class ServiceConfiguration { 26 | 27 | @Bean 28 | TestServiceImpl testService() { 29 | return new TestServiceImpl(); 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /tests/src/test/java/net/devh/boot/grpc/test/inject/CustomStub.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2023 The gRPC-Spring Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.devh.boot.grpc.test.inject; 18 | 19 | import io.grpc.CallOptions; 20 | import io.grpc.Channel; 21 | import io.grpc.stub.AbstractStub; 22 | 23 | /** 24 | * Simulates a custom stub type provided by a third party library, that requires a custom 25 | * {@link net.devh.boot.grpc.client.stubfactory.StubFactory StubFactory}. 26 | * 27 | * @param The type of the stub implementation. 28 | */ 29 | public abstract class CustomStub> extends AbstractStub { 30 | 31 | protected CustomStub(final Channel channel) { 32 | super(channel); 33 | } 34 | 35 | protected CustomStub(final Channel channel, final CallOptions callOptions) { 36 | super(channel, callOptions); 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /tests/src/test/java/net/devh/boot/grpc/test/inject/OtherStub.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2023 The gRPC-Spring Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.devh.boot.grpc.test.inject; 18 | 19 | import io.grpc.CallOptions; 20 | import io.grpc.Channel; 21 | import io.grpc.stub.AbstractStub; 22 | import net.devh.boot.grpc.client.stubfactory.FallbackStubFactory; 23 | 24 | /** 25 | * Simulates a custom stub type provided by a third party library, that can be created by the 26 | * {@link FallbackStubFactory}. 27 | * 28 | * @param The type of the stub implementation. 29 | */ 30 | public abstract class OtherStub> extends AbstractStub { 31 | 32 | protected OtherStub(final Channel channel) { 33 | super(channel); 34 | } 35 | 36 | protected OtherStub(final Channel channel, final CallOptions callOptions) { 37 | super(channel, callOptions); 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /tests/src/test/java/net/devh/boot/grpc/test/inject/metaannotation/GrpcClientWrapper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2023 The gRPC-Spring Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.devh.boot.grpc.test.inject.metaannotation; 18 | 19 | 20 | import java.lang.annotation.ElementType; 21 | import java.lang.annotation.Retention; 22 | import java.lang.annotation.RetentionPolicy; 23 | import java.lang.annotation.Target; 24 | 25 | import org.springframework.core.annotation.AliasFor; 26 | 27 | import io.grpc.ClientInterceptor; 28 | import net.devh.boot.grpc.client.inject.GrpcClient; 29 | 30 | @GrpcClient(value = "") 31 | @Retention(RetentionPolicy.RUNTIME) 32 | @Target({ElementType.FIELD, ElementType.METHOD}) 33 | public @interface GrpcClientWrapper { 34 | 35 | @AliasFor(annotation = GrpcClient.class, attribute = "value") 36 | String value(); 37 | 38 | @AliasFor(annotation = GrpcClient.class, attribute = "interceptors") 39 | Class[] interceptors() default {}; 40 | 41 | @AliasFor(annotation = GrpcClient.class, attribute = "interceptorNames") 42 | String[] interceptorNames() default {}; 43 | 44 | @AliasFor(annotation = GrpcClient.class, attribute = "sortInterceptors") 45 | boolean sortInterceptors() default false; 46 | 47 | String extraParamString(); 48 | 49 | boolean extraParamBoolean() default false; 50 | 51 | } 52 | -------------------------------------------------------------------------------- /tests/src/test/java/net/devh/boot/grpc/test/setup/InProcessSetupTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2023 The gRPC-Spring Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.devh.boot.grpc.test.setup; 18 | 19 | import org.springframework.boot.test.context.SpringBootTest; 20 | import org.springframework.test.annotation.DirtiesContext; 21 | import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; 22 | 23 | import lombok.extern.slf4j.Slf4j; 24 | import net.devh.boot.grpc.test.config.BaseAutoConfiguration; 25 | import net.devh.boot.grpc.test.config.InProcessConfiguration; 26 | import net.devh.boot.grpc.test.config.ServiceConfiguration; 27 | 28 | /** 29 | * A test checking that the server and client can start and connect to each other in process. 30 | * 31 | * @author Daniel Theuke (daniel.theuke@heuboe.de) 32 | */ 33 | @Slf4j 34 | @SpringBootTest 35 | @SpringJUnitConfig(classes = {InProcessConfiguration.class, ServiceConfiguration.class, BaseAutoConfiguration.class}) 36 | @DirtiesContext 37 | public class InProcessSetupTest extends AbstractSimpleServerClientTest { 38 | 39 | public InProcessSetupTest() { 40 | log.info("--- InProcessSetupTest ---"); 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /tests/src/test/java/net/devh/boot/grpc/test/setup/PlaintextSetupTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2023 The gRPC-Spring Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.devh.boot.grpc.test.setup; 18 | 19 | import org.springframework.boot.test.context.SpringBootTest; 20 | import org.springframework.test.annotation.DirtiesContext; 21 | import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; 22 | 23 | import lombok.extern.slf4j.Slf4j; 24 | import net.devh.boot.grpc.test.config.BaseAutoConfiguration; 25 | import net.devh.boot.grpc.test.config.ServiceConfiguration; 26 | 27 | /** 28 | * A test checking that the server and client can start and connect to each other with minimal config. 29 | * 30 | * @author Daniel Theuke (daniel.theuke@heuboe.de) 31 | */ 32 | @Slf4j 33 | @SpringBootTest(properties = { 34 | "grpc.client.GLOBAL.address=localhost:9090", 35 | "grpc.client.GLOBAL.negotiationType=PLAINTEXT" 36 | }) 37 | @SpringJUnitConfig(classes = {ServiceConfiguration.class, BaseAutoConfiguration.class}) 38 | @DirtiesContext 39 | public class PlaintextSetupTest extends AbstractSimpleServerClientTest { 40 | 41 | public PlaintextSetupTest() { 42 | log.info("--- PlaintextSetupTest ---"); 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /tests/src/test/java/net/devh/boot/grpc/test/setup/UnixSetupTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2023 The gRPC-Spring Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.devh.boot.grpc.test.setup; 18 | 19 | import org.junit.jupiter.api.condition.EnabledOnOs; 20 | import org.junit.jupiter.api.condition.OS; 21 | import org.springframework.boot.test.context.SpringBootTest; 22 | import org.springframework.test.annotation.DirtiesContext; 23 | import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; 24 | 25 | import lombok.extern.slf4j.Slf4j; 26 | import net.devh.boot.grpc.test.config.BaseAutoConfiguration; 27 | import net.devh.boot.grpc.test.config.ServiceConfiguration; 28 | 29 | /** 30 | * A test checking that the server and client can start and connect to each other with minimal config. 31 | * 32 | * @author Daniel Theuke (daniel.theuke@heuboe.de) 33 | */ 34 | @Slf4j 35 | @SpringBootTest(properties = { 36 | "grpc.server.address=unix:unix-test", 37 | "grpc.client.GLOBAL.address=unix:unix-test", 38 | "grpc.client.GLOBAL.negotiationType=PLAINTEXT", 39 | }) 40 | @SpringJUnitConfig(classes = {ServiceConfiguration.class, BaseAutoConfiguration.class}) 41 | @DirtiesContext 42 | @EnabledOnOs(OS.LINUX) 43 | public class UnixSetupTest extends AbstractSimpleServerClientTest { 44 | 45 | public UnixSetupTest() { 46 | log.info("--- UnixSetupTest ---"); 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /tests/src/test/java/net/devh/boot/grpc/test/util/DynamicTestCollection.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2023 The gRPC-Spring Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.devh.boot.grpc.test.util; 18 | 19 | import static org.junit.jupiter.api.DynamicTest.dynamicTest; 20 | 21 | import java.util.ArrayList; 22 | import java.util.Iterator; 23 | import java.util.List; 24 | 25 | import org.junit.jupiter.api.DynamicTest; 26 | import org.junit.jupiter.api.function.Executable; 27 | 28 | public class DynamicTestCollection implements Iterable { 29 | 30 | private final List tests = new ArrayList<>(); 31 | 32 | public static DynamicTestCollection create() { 33 | return new DynamicTestCollection(); 34 | } 35 | 36 | private DynamicTestCollection() {} 37 | 38 | @Override 39 | public Iterator iterator() { 40 | return this.tests.iterator(); 41 | } 42 | 43 | public DynamicTestCollection add(final String name, final Executable executable) { 44 | this.tests.add(dynamicTest(name, executable)); 45 | return this; 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /tests/src/test/java/net/devh/boot/grpc/test/util/EnableOnIPv6.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2023 The gRPC-Spring Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.devh.boot.grpc.test.util; 18 | 19 | import static java.lang.annotation.ElementType.ANNOTATION_TYPE; 20 | import static java.lang.annotation.ElementType.METHOD; 21 | import static java.lang.annotation.ElementType.TYPE; 22 | 23 | import java.lang.annotation.Retention; 24 | import java.lang.annotation.RetentionPolicy; 25 | import java.lang.annotation.Target; 26 | 27 | import org.junit.jupiter.api.extension.ExtendWith; 28 | 29 | /** 30 | * An annotation for JUnit tests that will enable the test if the current host has an IPv6 loopback address. 31 | * 32 | * @author Daniel Theuke (daniel.theuke@heuboe.de) 33 | */ 34 | @Target({METHOD, TYPE, ANNOTATION_TYPE}) 35 | @Retention(RetentionPolicy.RUNTIME) 36 | @ExtendWith(RequireIPv6Condition.class) 37 | public @interface EnableOnIPv6 { 38 | } 39 | -------------------------------------------------------------------------------- /tests/src/test/java/net/devh/boot/grpc/test/util/LoggerTestUtil.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2023 The gRPC-Spring Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.devh.boot.grpc.test.util; 18 | 19 | import java.util.Arrays; 20 | 21 | import org.slf4j.LoggerFactory; 22 | import org.springframework.lang.Nullable; 23 | 24 | import ch.qos.logback.classic.Logger; 25 | import ch.qos.logback.classic.spi.ILoggingEvent; 26 | import ch.qos.logback.core.read.ListAppender; 27 | 28 | /** 29 | * Class to test proper @Slf4j logging. 30 | * 31 | * @author Andjelko Perisic (andjelko.perisic@gmail.com) 32 | */ 33 | public class LoggerTestUtil { 34 | 35 | private LoggerTestUtil() { 36 | throw new UnsupportedOperationException("Util class not to be instantiated."); 37 | } 38 | 39 | 40 | public static ListAppender getListAppenderForClasses(@Nullable Class... classList) { 41 | 42 | ListAppender loggingEventListAppender = new ListAppender<>(); 43 | loggingEventListAppender.start(); 44 | 45 | if (classList == null) { 46 | return loggingEventListAppender; 47 | } 48 | 49 | Arrays.stream(classList) 50 | .map(clazz -> (Logger) LoggerFactory.getLogger(clazz)) 51 | .forEach(log -> log.addAppender(loggingEventListAppender)); 52 | 53 | return loggingEventListAppender; 54 | } 55 | 56 | } 57 | -------------------------------------------------------------------------------- /tests/src/test/java/net/devh/boot/grpc/test/util/TriConsumer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2023 The gRPC-Spring Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.devh.boot.grpc.test.util; 18 | 19 | @FunctionalInterface 20 | public interface TriConsumer { 21 | 22 | void accept(S s, T t, U u); 23 | 24 | } 25 | -------------------------------------------------------------------------------- /tests/src/test/kotlin/net/devh/boot/grpc/test/kotlin/inject/ConstructorInjectionAnotherTestContainer.kt: -------------------------------------------------------------------------------- 1 | package net.devh.boot.grpc.test.kotlin.inject 2 | 3 | import net.devh.boot.grpc.client.inject.GrpcClient 4 | import net.devh.boot.grpc.test.proto.TestServiceGrpc 5 | import org.springframework.stereotype.Component 6 | 7 | /** 8 | * Another client stubs bean container for testing constructor inject. 9 | * Test multiple @GrpcClient with same configs among project wouldn't affect registering of client stub beans. 10 | */ 11 | @Component 12 | class ConstructorInjectionAnotherTestContainer( 13 | @GrpcClient("test") 14 | val blockingStub: TestServiceGrpc.TestServiceBlockingStub, 15 | 16 | @GrpcClient("unnamed") 17 | val unnamedTestServiceBlockingStub: TestServiceGrpc.TestServiceBlockingStub, 18 | ) -------------------------------------------------------------------------------- /tests/src/test/kotlin/net/devh/boot/grpc/test/kotlin/inject/ConstructorInjectionTestContainer.kt: -------------------------------------------------------------------------------- 1 | package net.devh.boot.grpc.test.kotlin.inject 2 | 3 | import io.grpc.Channel 4 | import net.devh.boot.grpc.client.inject.GrpcClient 5 | import net.devh.boot.grpc.test.inject.CustomGrpc 6 | import net.devh.boot.grpc.test.proto.TestServiceGrpc 7 | import net.devh.boot.grpc.test.proto.TestServiceGrpc.TestServiceBlockingStub 8 | import org.springframework.stereotype.Component 9 | 10 | /** 11 | * A client stubs bean container for testing constructor inject 12 | */ 13 | @Component 14 | class ConstructorInjectionTestContainer( 15 | 16 | @GrpcClient("test") 17 | val channel: Channel, 18 | 19 | @GrpcClient("test") 20 | val stub: TestServiceGrpc.TestServiceStub, 21 | 22 | @GrpcClient("test") 23 | val blockingStub: TestServiceBlockingStub, 24 | 25 | @GrpcClient("test") 26 | val futureStubForClientTest: TestServiceGrpc.TestServiceFutureStub, 27 | 28 | @GrpcClient("anotherTest") 29 | val anotherBlockingStub: TestServiceBlockingStub, 30 | 31 | @GrpcClient("unnamed") 32 | val unnamedTestServiceBlockingStub: TestServiceBlockingStub, 33 | 34 | @GrpcClient("test") 35 | val anotherServiceClientBean: CustomGrpc.FactoryMethodAccessibleStub, 36 | ) -------------------------------------------------------------------------------- /tests/src/test/kotlin/net/devh/boot/grpc/test/kotlin/inject/GrpcClientBeanCustomConfig.kt: -------------------------------------------------------------------------------- 1 | package net.devh.boot.grpc.test.kotlin.inject 2 | 3 | import io.grpc.stub.AbstractStub 4 | import net.devh.boot.grpc.client.inject.GrpcClient 5 | import net.devh.boot.grpc.client.inject.GrpcClientBean 6 | import net.devh.boot.grpc.client.stubfactory.StandardJavaGrpcStubFactory 7 | import net.devh.boot.grpc.client.stubfactory.StubFactory 8 | import net.devh.boot.grpc.test.inject.CustomStub 9 | import net.devh.boot.grpc.test.proto.TestServiceGrpc 10 | import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean 11 | import org.springframework.boot.test.context.TestConfiguration 12 | import org.springframework.context.annotation.Bean 13 | 14 | @GrpcClientBean( 15 | clazz = TestServiceGrpc.TestServiceBlockingStub::class, 16 | beanName = "stubFromSpringConfiguration", 17 | client = GrpcClient("test2") 18 | ) 19 | @TestConfiguration 20 | open class GrpcClientBeanCustomConfig{ 21 | 22 | @Bean 23 | @ConditionalOnMissingBean(name = ["customStubFactory"]) 24 | open fun customStubFactory(): StubFactory = 25 | object : StandardJavaGrpcStubFactory() { 26 | 27 | override fun isApplicable(stubType: Class>): Boolean = 28 | CustomStub::class.java.isAssignableFrom(stubType) 29 | 30 | override fun getFactoryMethodName(): String = 31 | "custom" 32 | } 33 | } -------------------------------------------------------------------------------- /tests/src/test/kotlin/net/devh/boot/grpc/test/kotlin/inject/GrpcClientBeanTestConfig.kt: -------------------------------------------------------------------------------- 1 | package net.devh.boot.grpc.test.kotlin.inject 2 | 3 | import net.devh.boot.grpc.client.inject.GrpcClient 4 | import net.devh.boot.grpc.client.inject.GrpcClientBean 5 | import net.devh.boot.grpc.test.inject.CustomGrpc 6 | import net.devh.boot.grpc.test.proto.TestServiceGrpc 7 | import org.springframework.beans.factory.annotation.Qualifier 8 | import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean 9 | import org.springframework.boot.test.context.TestConfiguration 10 | import org.springframework.context.annotation.Bean 11 | 12 | @GrpcClientBean( 13 | clazz = TestServiceGrpc.TestServiceBlockingStub::class, 14 | beanName = "blockingStub", 15 | client = GrpcClient("test") 16 | ) 17 | @GrpcClientBean( 18 | clazz = TestServiceGrpc.TestServiceFutureStub::class, 19 | beanName = "futureStubForClientTest", 20 | client = GrpcClient("test") 21 | ) 22 | @GrpcClientBean( 23 | clazz = TestServiceGrpc.TestServiceBlockingStub::class, 24 | beanName = "anotherBlockingStub", 25 | client = GrpcClient("anotherTest") 26 | ) 27 | @GrpcClientBean( 28 | clazz = TestServiceGrpc.TestServiceBlockingStub::class, 29 | client = GrpcClient("unnamed") 30 | ) 31 | @GrpcClientBean( 32 | clazz = CustomGrpc.FactoryMethodAccessibleStub::class, 33 | beanName = "anotherServiceClientBean", 34 | client = GrpcClient("test") 35 | ) 36 | @TestConfiguration 37 | open class GrpcClientBeanTestConfig { 38 | 39 | @Bean 40 | @ConditionalOnMissingBean(name = ["aboutMethodInjectedBlockingStubBean"]) 41 | open fun aboutMethodInjectedBlockingStubBean( 42 | @Qualifier("anotherBlockingStub") blockingStub: TestServiceGrpc.TestServiceBlockingStub 43 | ): String = 44 | blockingStub.toString() 45 | 46 | } -------------------------------------------------------------------------------- /tests/src/test/kotlin/net/devh/boot/grpc/test/kotlin/inject/InjectionTestContainer.kt: -------------------------------------------------------------------------------- 1 | package net.devh.boot.grpc.test.kotlin.inject 2 | 3 | import io.grpc.Channel 4 | import net.devh.boot.grpc.client.inject.GrpcClient 5 | import net.devh.boot.grpc.test.inject.CustomGrpc 6 | import net.devh.boot.grpc.test.proto.TestServiceGrpc 7 | import org.springframework.stereotype.Component 8 | 9 | /** 10 | * A client stubs bean container for testing constructor inject 11 | */ 12 | @Component 13 | class InjectionTestContainer { 14 | 15 | @GrpcClient("test") 16 | lateinit var channel: Channel 17 | 18 | @GrpcClient("test") 19 | lateinit var stub: TestServiceGrpc.TestServiceStub 20 | 21 | @GrpcClient("test") 22 | lateinit var blockingStub: TestServiceGrpc.TestServiceBlockingStub 23 | 24 | @GrpcClient("test") 25 | lateinit var futureStubForClientTest: TestServiceGrpc.TestServiceFutureStub 26 | 27 | @GrpcClient("anotherTest") 28 | lateinit var anotherBlockingStub: TestServiceGrpc.TestServiceBlockingStub 29 | 30 | @GrpcClient("unnamed") 31 | lateinit var unnamedTestServiceBlockingStub: TestServiceGrpc.TestServiceBlockingStub 32 | 33 | @GrpcClient("test") 34 | lateinit var anotherServiceClientBean: CustomGrpc.FactoryMethodAccessibleStub 35 | } -------------------------------------------------------------------------------- /tests/src/test/kotlin/net/devh/boot/grpc/test/kotlin/inject/KotlinGrpcClientBeanConstructorInjectionTest.kt: -------------------------------------------------------------------------------- 1 | package net.devh.boot.grpc.test.kotlin.inject 2 | 3 | import net.devh.boot.grpc.test.config.BaseAutoConfiguration 4 | import net.devh.boot.grpc.test.config.InProcessConfiguration 5 | import net.devh.boot.grpc.test.config.ServiceConfiguration 6 | import org.junit.jupiter.api.Test 7 | import org.springframework.beans.factory.annotation.Autowired 8 | import org.springframework.boot.test.context.SpringBootTest 9 | import org.springframework.test.annotation.DirtiesContext 10 | import org.springframework.test.context.junit.jupiter.SpringJUnitConfig 11 | import kotlin.test.assertNotNull 12 | 13 | @SpringBootTest 14 | @SpringJUnitConfig( 15 | classes = [ 16 | ConstructorInjectionTestContainer::class, 17 | GrpcClientBeanTestConfig::class, 18 | GrpcClientBeanCustomConfig::class, 19 | InProcessConfiguration::class, 20 | ServiceConfiguration::class, 21 | BaseAutoConfiguration::class 22 | ] 23 | ) 24 | @DirtiesContext 25 | class KotlinGrpcClientBeanConstructorInjectionTest { 26 | 27 | @Autowired 28 | lateinit var container: ConstructorInjectionTestContainer 29 | 30 | /** 31 | * `@GrpcClientBean` together with `@GrpcClient` annotated constructor parameter for Kotlin constructor injection. 32 | */ 33 | @Test 34 | fun testGrpcClientBeanConstructorInjection() { 35 | assert(::container.isInitialized) 36 | assertNotNull(container.blockingStub) 37 | } 38 | 39 | } 40 | 41 | 42 | -------------------------------------------------------------------------------- /tests/src/test/kotlin/net/devh/boot/grpc/test/kotlin/inject/KotlinGrpcClientBeanInjectionTest.kt: -------------------------------------------------------------------------------- 1 | package net.devh.boot.grpc.test.kotlin.inject 2 | 3 | import net.devh.boot.grpc.test.config.BaseAutoConfiguration 4 | import net.devh.boot.grpc.test.config.InProcessConfiguration 5 | import net.devh.boot.grpc.test.config.ServiceConfiguration 6 | import org.junit.jupiter.api.Test 7 | import org.springframework.beans.factory.annotation.Autowired 8 | import org.springframework.boot.test.context.SpringBootTest 9 | import org.springframework.test.annotation.DirtiesContext 10 | import org.springframework.test.context.junit.jupiter.SpringJUnitConfig 11 | import kotlin.test.assertNotNull 12 | 13 | @SpringBootTest 14 | @SpringJUnitConfig( 15 | classes = [ 16 | InjectionTestContainer::class, 17 | GrpcClientBeanTestConfig::class, 18 | GrpcClientBeanCustomConfig::class, 19 | InProcessConfiguration::class, 20 | ServiceConfiguration::class, 21 | BaseAutoConfiguration::class 22 | ] 23 | ) 24 | @DirtiesContext 25 | class KotlinGrpcClientBeanInjectionTest { 26 | 27 | @Autowired 28 | lateinit var container: InjectionTestContainer 29 | 30 | /** 31 | * `@GrpcClientBean` for Kotlin property injection. 32 | */ 33 | @Test 34 | fun testGrpcClientBeanPropertyInjection() { 35 | assert(::container.isInitialized) 36 | assertNotNull(container.blockingStub) 37 | } 38 | } -------------------------------------------------------------------------------- /tests/src/test/kotlin/net/devh/boot/grpc/test/kotlin/inject/KotlinGrpcClientConstructorInjectionTest.kt: -------------------------------------------------------------------------------- 1 | package net.devh.boot.grpc.test.kotlin.inject 2 | 3 | import net.devh.boot.grpc.test.config.BaseAutoConfiguration 4 | import net.devh.boot.grpc.test.config.InProcessConfiguration 5 | import net.devh.boot.grpc.test.config.ServiceConfiguration 6 | import org.junit.jupiter.api.Test 7 | import org.springframework.beans.factory.annotation.Autowired 8 | import org.springframework.boot.test.context.SpringBootTest 9 | import org.springframework.test.annotation.DirtiesContext 10 | import org.springframework.test.context.junit.jupiter.SpringJUnitConfig 11 | import kotlin.test.assertNotNull 12 | 13 | @SpringBootTest() 14 | @SpringJUnitConfig( 15 | classes = [ 16 | ConstructorInjectionTestContainer::class, 17 | ConstructorInjectionAnotherTestContainer::class, 18 | InProcessConfiguration::class, 19 | ServiceConfiguration::class, 20 | BaseAutoConfiguration::class, 21 | ] 22 | ) 23 | @DirtiesContext 24 | class KotlinGrpcClientConstructorInjectionTest { 25 | 26 | @Autowired 27 | lateinit var bean: ConstructorInjectionTestContainer 28 | 29 | @Autowired 30 | lateinit var anotherBean: ConstructorInjectionAnotherTestContainer 31 | 32 | /** 33 | * `@GrpcClient` annotated constructor parameter for Kotlin constructor injection. 34 | */ 35 | @Test 36 | fun testConstructorInjection() { 37 | assert(::bean.isInitialized) 38 | assert(::anotherBean.isInitialized) 39 | assertNotNull(bean.blockingStub, "blockingStub") 40 | assertNotNull(bean.anotherServiceClientBean, "anotherServiceClientBean") 41 | assertNotNull(anotherBean.blockingStub, "anotherContainerBlockingStub") 42 | } 43 | } -------------------------------------------------------------------------------- /tests/src/test/proto/TestService.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | import "google/protobuf/empty.proto"; 4 | 5 | option java_multiple_files = true; 6 | option java_package = "net.devh.boot.grpc.test.proto"; 7 | option java_outer_classname = "TestServiceProto"; 8 | 9 | service TestService { 10 | 11 | // Returns version information 12 | rpc normal(google.protobuf.Empty) returns (SomeType) {} 13 | 14 | // Fails with an error 15 | rpc error(google.protobuf.Empty) returns (google.protobuf.Empty) {} 16 | 17 | // Unimplemented method 18 | rpc unimplemented(google.protobuf.Empty) returns (SomeType) {} 19 | 20 | // Returns the incoming requests as is. 21 | rpc echo(stream SomeType) returns (stream SomeType) {} 22 | 23 | // Secured method 24 | rpc secure(google.protobuf.Empty) returns (SomeType) {} 25 | 26 | // Secured method with only multiple requests 27 | rpc secureDrain(stream SomeType) returns (google.protobuf.Empty) {} 28 | 29 | // Secured method with only multiple answers 30 | rpc secureSupply(google.protobuf.Empty) returns (stream SomeType) {} 31 | 32 | // Secured method with both multiple requests and answers 33 | rpc secureBidi(stream SomeType) returns (stream SomeType) {} 34 | 35 | } 36 | 37 | message SomeType { 38 | string version = 1; 39 | } 40 | -------------------------------------------------------------------------------- /tests/src/test/resources/certificates/client1.crt: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIIE9zCCAt+gAwIBAgIJAPnoUKl4HMFdMA0GCSqGSIb3DQEBCwUAMBIxEDAOBgNV 3 | BAMMB2NsaWVudDEwHhcNMTgxMDMwMTYwOTM2WhcNMjgxMDI3MTYwOTM2WjASMRAw 4 | DgYDVQQDDAdjbGllbnQxMIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEA 5 | 1RY1x0KZuWPAKCSkdLSfBMK3SWiqt3JZQEL50SyjbHRxPza+igfxvXCFW7jxRX2b 6 | DRSN7m9RYB5HYz55hHUxNDq4n4O3ciB9NdNrt4LCgpRu9gy8Sj4J16H1zssJU0D2 7 | APtNaLKbZOcfyAev4dPBVObmis/TAhSF/QTSNnWBdVgA0+p0DMZ6M+F5qNpZKltn 8 | VEu8j19BfFckRMZglkhhTMiI/0kzbr9Yki+OZCCLZBARFrFw3ZELTbGL/ezpPqjq 9 | hpYkGFB39yyQmfeXKLMEOXPiyCCvXk6YZrwfItrXzVDh4HJq/SAQaoMs0t2csj5C 10 | O4bixf9MD4o/jqvlLwQX0XjbbDLtNgUVeIhNEtF91NXcuYO8sCXLY12roy1RWR5f 11 | 9/Q7a6i5YNTBR0BZHLBNas34PziefAQrwU50djQ7lecm3RDKWHrz0WtVNH/Fugb7 12 | KLh+i47dh/mpJ/0wC9Xdb17E8wFLCF7viDT+Uh4UC/Rpr/3v4zGjBv6Cs/9oIaza 13 | W4BxfoSsEy+ZiFWl0Ud07wl23sqUGgM4ZzcyHYv57zG3n/SFzMJ0UDF4FbGF2U/9 14 | PIbBy6QbAZbI6/WQXuWBFleyE7BDwQS/YF4WjIOGY7llhwyLSQi6EXurAR2ECYDE 15 | njqvTfcLvphoM5Jn0c97Mi7PYr/mmKqX2Jv+SbW4Eq8CAwEAAaNQME4wHQYDVR0O 16 | BBYEFDlQ8/CY8881ZjnMq9qBaOzmjmC2MB8GA1UdIwQYMBaAFDlQ8/CY8881ZjnM 17 | q9qBaOzmjmC2MAwGA1UdEwQFMAMBAf8wDQYJKoZIhvcNAQELBQADggIBAH4iOBLQ 18 | oi2C2HPMqE8314Fv0swr8yjwHNf9vDvAkL939E/PUAxwSpaR7Gcxik8jauzbqqQM 19 | gfZyGVXO3EJEXL5+XgkrcSeoWHfgGLa4saqsb+kIgStrI4iP5OFVrAgDuUh6WPYI 20 | b3qQeQYblyLwuc25sboTJDqen9xMoEYXa4wWgNSLFdvupUJkKCZ6LBAT579lAZeV 21 | Bb8+4JH/JmXUkPzfN7lJXlAelwqNSs2cQVx+RIrYp+Dz9BafYZMgS1MsqHR3XltK 22 | 5rsqdFp6WQt5fy0M8ZXm6jkv7szJtvFVBJB036pk3RUVJv8hUI6NBqipFM8vzXb8 23 | eWFp9AmXfjUBAPhSrfhNCORTfzDJswOTmWq1I73m43Pnwe6hx6QILjroIZNSA5Am 24 | Peu1+hv/Gkj5EdfZdlIgf6I8BuEjlMpffhKt9Yn4tYV3o9yWo8peeLawT4avqBVd 25 | 02K9g7i5+YpMHZ5s+enWgy+/YVWNvH/3coNHTHDMNvmEy3EHfzswgnB9qkYUsj1W 26 | kujB0PKBYvTRnIxry6UPGXh7i8WSOk67160lwTZMCxIZGuJAPu47n8ADCObOA8/T 27 | 3OE5kKWX7Gw3Hi2Nu3IWF7DAeYN2oMurqmigN9nl/dZKhJThZUZ1G3SBwXtT7mj1 28 | UOP7pQbCYj/fdqoMpwFPak+fQ+qHU3ostbsV 29 | -----END CERTIFICATE----- 30 | -------------------------------------------------------------------------------- /tests/src/test/resources/certificates/client1.jks: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/grpc-ecosystem/grpc-spring/b83afe68cef63edc7dfeec694bc279956bbc8c3d/tests/src/test/resources/certificates/client1.jks -------------------------------------------------------------------------------- /tests/src/test/resources/certificates/client1.p12: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/grpc-ecosystem/grpc-spring/b83afe68cef63edc7dfeec694bc279956bbc8c3d/tests/src/test/resources/certificates/client1.p12 -------------------------------------------------------------------------------- /tests/src/test/resources/certificates/client2.crt: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIIE9zCCAt+gAwIBAgIJAITU3DA0N61EMA0GCSqGSIb3DQEBCwUAMBIxEDAOBgNV 3 | BAMMB2NsaWVudDIwHhcNMTgxMDMwMTYwOTM2WhcNMjgxMDI3MTYwOTM2WjASMRAw 4 | DgYDVQQDDAdjbGllbnQyMIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEA 5 | wnfZ3NfEJEyyuKJ+v6R/qIBjHvdwwy1CPLquGI08YnOpW/MEIYHUJZ7C3JNFKkCI 6 | g8VqFvsI9cho2lpSpucAly4T40js/2gRuUVKrCeOQDy22ihDVpmOCGINEqnRzSm8 7 | nEXgmPnuBssZ3zvHk3xA1W4A/JzjFM2elZiXozoxj77wNSdxGS1nWsCDSkjXsxxA 8 | h3I2KW/N+SJmH7r61uL8/zyHsrYX664OpdRXkq16iRbT0JGLWXTWr2CqtwCEtpQi 9 | AAFUo9CJTYtxL3viSeDqQDcHmTCzIsWuwmoc0VIpkKYG7877vn91BUG9qy75UZLW 10 | n0w5N1yPaYjsoUbTEXXv8KSUP+iwdzcB5NiRcygXzOmu3/+zG6wC9OjAIjfD1qm8 11 | d1uWojKqdt1X1XWqCTXJJZLn1djU2L0vPxmdcFjOHYufc0VwZ/N1I/K7/wOofE1L 12 | oYWd9Pn0Hi7Wpu6JnWpzLVp/hfRLqwzdPXRwH6aiQIb5wSC2wHtp+lZE2Sx5ZnjW 13 | 0e+ktMUyF4YMfAHFNCpwZVMdhA3FSGnSlfZn1HLpWqTTxhofgMvbnJEZ2EIyJsTJ 14 | FtRbfDzcjRDeMHvnnYAciTDQd1uB32qeLM16BsT9xeSIviZiDuz9RJixPn9NDG/i 15 | dazyRkq70im1Il1DRY+yShe0IZGat/HlbmZHmB97fZsCAwEAAaNQME4wHQYDVR0O 16 | BBYEFIgQJ961yXwGcoqPBUcUx7m95DXfMB8GA1UdIwQYMBaAFIgQJ961yXwGcoqP 17 | BUcUx7m95DXfMAwGA1UdEwQFMAMBAf8wDQYJKoZIhvcNAQELBQADggIBABW12bdx 18 | G1zVT8rPL8afZ6zdLmGPlIdF+ARqh2nxpD2W/8Z6fulJ+/SsJJcZTFApz4337adJ 19 | 85i41z0SDzS1Zcf0blgnNPDBZF0U1odVPVqBYgVQbzNHosty9j3pPZi17QHzz7EM 20 | TXXkvoZ2a/agotAmmhn2Zbg4G/6CYsfAy8FM/KG4uFgOIVBdlT8ELXm52M5JNVzr 21 | 0TncHz6FauRNw5mXicvbwZnkjyOUQzx+0fKO5ojPoeqXGzx0QndZkulx+OLI/7JD 22 | CybbAfgM83ll1ix7DjVGUiySo5UEJZw/pPdKcrnmvgoN0Wmbm/MXfmwD9eYPIyoZ 23 | rhxxdg/h/SYlu6Pc/qinx8EARmVa2FVbd0Ajo6yLAsQyAD4P9qc0+gDkQQfm4UE+ 24 | XK5/jIwJ6NxAawPFVM4HIw0kTVfCDaiZ1f06enic0wKmtIE9h2gPpG9dhAEnpzv7 25 | +a50NNC1B94SNcJHktB599mdEuFxr7Vtfw7GR1vJieHAYcFXSbkTtmeoOMVbDx3H 26 | RqR4V+AfMTrEBj5fh7TC/2KT3nXHy4JxOM9364APiOVe8Xqlo1w7RDokzwD2IkFv 27 | gHCujHb9ijxjyF2OYb0fJxpBSOqrKqCjifDnUPEzFWPCj1YnMDtKIv/ykqMn8Ggj 28 | P9V4+P7NgLkkZTOz6Qo/bLe/75xEQLX2TsV3 29 | -----END CERTIFICATE----- 30 | -------------------------------------------------------------------------------- /tests/src/test/resources/certificates/client2.jks: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/grpc-ecosystem/grpc-spring/b83afe68cef63edc7dfeec694bc279956bbc8c3d/tests/src/test/resources/certificates/client2.jks -------------------------------------------------------------------------------- /tests/src/test/resources/certificates/client2.p12: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/grpc-ecosystem/grpc-spring/b83afe68cef63edc7dfeec694bc279956bbc8c3d/tests/src/test/resources/certificates/client2.p12 -------------------------------------------------------------------------------- /tests/src/test/resources/certificates/generateCertificates.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | echo "Generating certificates" 4 | openssl req -x509 -nodes -subj "//CN=localhost" -newkey rsa:4096 -sha256 -keyout server.key -out server.crt -days 3650 5 | openssl req -x509 -nodes -subj "//CN=client1" -newkey rsa:4096 -sha256 -keyout client1.key -out client1.crt -days 3650 6 | openssl req -x509 -nodes -subj "//CN=client2" -newkey rsa:4096 -sha256 -keyout client2.key -out client2.crt -days 3650 7 | 8 | echo "Generating trustCertCollection" 9 | cat server.crt > trusted-servers-collection 10 | cat client1.crt client2.crt > trusted-clients-collection 11 | 12 | echo "Creating p12 key and trust stores" 13 | openssl pkcs12 -export -name server -in server.crt -inkey server.key -passout 'pass:' -out server.p12 14 | openssl pkcs12 -export -name client1 -in client1.crt -inkey client1.key -passout 'pass:' -out client1.p12 15 | openssl pkcs12 -export -name client2 -in client2.crt -inkey client2.key -passout 'pass:' -out client2.p12 16 | 17 | # create trusted-clients.p12 and trusted-servers.p12 via keystore-explorer and java 8 18 | # create *.jks by opening the p12 variants and saving this as jks 19 | echo "--- DONE ---" 20 | -------------------------------------------------------------------------------- /tests/src/test/resources/certificates/server.crt: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIIE+zCCAuOgAwIBAgIJAPaN4CpLQzLtMA0GCSqGSIb3DQEBCwUAMBQxEjAQBgNV 3 | BAMMCWxvY2FsaG9zdDAeFw0xODEwMjYxNDI2MDVaFw0yODEwMjMxNDI2MDVaMBQx 4 | EjAQBgNVBAMMCWxvY2FsaG9zdDCCAiIwDQYJKoZIhvcNAQEBBQADggIPADCCAgoC 5 | ggIBALYsfU9sSTCsO5+ksdLi2CwPAl2EFuVL7KbwCDxkeOh733ckWbdLE4guTvtj 6 | kGff/dOaGhdUnqSr4CTZRDJKmkzdHeTZToChhOu4cfr//uzk90yF4j0XzUB0Aye0 7 | F/fHaY4XjPAnwfZf8Xuy7JCJ8WCBvK9SrxMxpwTEpCL3QIjHYeA/UTBjI/xo0LF7 8 | VIncRiJQnpmS9TuM6dnvJ38ezfP+fzF+8izjvX7J5rooTbgDxXNSvdoHv76C/TQR 9 | ANTV+M+zLuDb/sl5gMWOHRpkzj4BFDUScdHU4uKT7XXkqdfNxg8rIzxrUGNXoBvL 10 | 4ETLbegkhqIY3oCtR+tbKE1145mRFjcOzvkHmhGqTkCdCIKcTn5ReXjgeSQDjlRX 11 | VEwvBQlCSfyDlnaKy2adWAC7H1SW2PVwCALCgA88kmJEmqbOJcOiNiKFDzHaBhVw 12 | 7hSGrXa3Wfj7wdWrdtoQLtSc2MkR0qNcfnEPKGz+sU/cLtdbB19ut36UbfRJAyC7 13 | galsHtvLDVRWnm/z1uWUStNye7S9EDCEbiG802jwnnlfzLdpkmuTnliNngg2jJO2 14 | EX1HYXzT4ezsMJLZV20uAm2VUt9fXDnyofEpLRIxTcQVD9mzIYh92EK6yCcXf2ms 15 | golS3pLAYWMy3OQ5Xfb+aZoYdnZVWFl0B23LlkniPE011HGlAgMBAAGjUDBOMB0G 16 | A1UdDgQWBBTlnzunEY+CaZH5qymJRwDBqz14RDAfBgNVHSMEGDAWgBTlnzunEY+C 17 | aZH5qymJRwDBqz14RDAMBgNVHRMEBTADAQH/MA0GCSqGSIb3DQEBCwUAA4ICAQBs 18 | we7UZl/BDKKjq+CFycF8UKORoHx0UVBZh7WQxzL4o89lTAbBs4drVLS6Q/YBoFLp 19 | WhCdtPeIW+Snm2YIAFQXvgCoZZ0vDQwmsjBCXI7/K9WvPvylYF9sV53foyppEZAy 20 | ZRosESq0407I0bTx3F5Fs6OxI6cc9DhMHmdj/YZ1/BcHZZQPSmbBW+82Dh3qB1ez 21 | AQpEwi+9kW0nAbxK5SIBzfH3EW/XNeIZF3AAp+4JQdXi64utnrq2PByNvy2ac6xo 22 | rP4hQIPRdnzotDPtK/81BA4ZuHHh2bkvEkEq3m/3KRQG3qIigYOwHWPcFFHef2Pj 23 | vDJ/ah+/oAYTiH52H+zThUn9FfjeBfSJDpwsbAz34PQVhdFvahcuKEEeRolsUWTS 24 | pXS0F0aecae+2uC0UUPSXSmQ11tgddBwmpTb3VEjXGdw0q+4ZCN25L6Oir/fmmSs 25 | 7Vqw9lkWKsSSpKPAsydHUJHZFAWdjEEQcGq4wb9sY8hWk8sQAvrISNZtNTikjzZr 26 | hf42E+j5DTaAjNu2oMStzydVzCE5bhpZ+0rPcKdghA+6etNPtt+LwxzYpSrrlo7E 27 | nCW2u6ZUm6JXON2u/INhoGQIXX1XWuDObfn2/5XwcC1lcYvgXiUJhtSzMQEwPi6H 28 | o10MR/UJTafCwx5Fj5bkecYvbYkcwRNXi3W5cpSCLg== 29 | -----END CERTIFICATE----- 30 | -------------------------------------------------------------------------------- /tests/src/test/resources/certificates/server.jks: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/grpc-ecosystem/grpc-spring/b83afe68cef63edc7dfeec694bc279956bbc8c3d/tests/src/test/resources/certificates/server.jks -------------------------------------------------------------------------------- /tests/src/test/resources/certificates/server.p12: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/grpc-ecosystem/grpc-spring/b83afe68cef63edc7dfeec694bc279956bbc8c3d/tests/src/test/resources/certificates/server.p12 -------------------------------------------------------------------------------- /tests/src/test/resources/certificates/trusted-clients.jks: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/grpc-ecosystem/grpc-spring/b83afe68cef63edc7dfeec694bc279956bbc8c3d/tests/src/test/resources/certificates/trusted-clients.jks -------------------------------------------------------------------------------- /tests/src/test/resources/certificates/trusted-clients.p12: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/grpc-ecosystem/grpc-spring/b83afe68cef63edc7dfeec694bc279956bbc8c3d/tests/src/test/resources/certificates/trusted-clients.p12 -------------------------------------------------------------------------------- /tests/src/test/resources/certificates/trusted-servers-collection: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIIE+zCCAuOgAwIBAgIJAPaN4CpLQzLtMA0GCSqGSIb3DQEBCwUAMBQxEjAQBgNV 3 | BAMMCWxvY2FsaG9zdDAeFw0xODEwMjYxNDI2MDVaFw0yODEwMjMxNDI2MDVaMBQx 4 | EjAQBgNVBAMMCWxvY2FsaG9zdDCCAiIwDQYJKoZIhvcNAQEBBQADggIPADCCAgoC 5 | ggIBALYsfU9sSTCsO5+ksdLi2CwPAl2EFuVL7KbwCDxkeOh733ckWbdLE4guTvtj 6 | kGff/dOaGhdUnqSr4CTZRDJKmkzdHeTZToChhOu4cfr//uzk90yF4j0XzUB0Aye0 7 | F/fHaY4XjPAnwfZf8Xuy7JCJ8WCBvK9SrxMxpwTEpCL3QIjHYeA/UTBjI/xo0LF7 8 | VIncRiJQnpmS9TuM6dnvJ38ezfP+fzF+8izjvX7J5rooTbgDxXNSvdoHv76C/TQR 9 | ANTV+M+zLuDb/sl5gMWOHRpkzj4BFDUScdHU4uKT7XXkqdfNxg8rIzxrUGNXoBvL 10 | 4ETLbegkhqIY3oCtR+tbKE1145mRFjcOzvkHmhGqTkCdCIKcTn5ReXjgeSQDjlRX 11 | VEwvBQlCSfyDlnaKy2adWAC7H1SW2PVwCALCgA88kmJEmqbOJcOiNiKFDzHaBhVw 12 | 7hSGrXa3Wfj7wdWrdtoQLtSc2MkR0qNcfnEPKGz+sU/cLtdbB19ut36UbfRJAyC7 13 | galsHtvLDVRWnm/z1uWUStNye7S9EDCEbiG802jwnnlfzLdpkmuTnliNngg2jJO2 14 | EX1HYXzT4ezsMJLZV20uAm2VUt9fXDnyofEpLRIxTcQVD9mzIYh92EK6yCcXf2ms 15 | golS3pLAYWMy3OQ5Xfb+aZoYdnZVWFl0B23LlkniPE011HGlAgMBAAGjUDBOMB0G 16 | A1UdDgQWBBTlnzunEY+CaZH5qymJRwDBqz14RDAfBgNVHSMEGDAWgBTlnzunEY+C 17 | aZH5qymJRwDBqz14RDAMBgNVHRMEBTADAQH/MA0GCSqGSIb3DQEBCwUAA4ICAQBs 18 | we7UZl/BDKKjq+CFycF8UKORoHx0UVBZh7WQxzL4o89lTAbBs4drVLS6Q/YBoFLp 19 | WhCdtPeIW+Snm2YIAFQXvgCoZZ0vDQwmsjBCXI7/K9WvPvylYF9sV53foyppEZAy 20 | ZRosESq0407I0bTx3F5Fs6OxI6cc9DhMHmdj/YZ1/BcHZZQPSmbBW+82Dh3qB1ez 21 | AQpEwi+9kW0nAbxK5SIBzfH3EW/XNeIZF3AAp+4JQdXi64utnrq2PByNvy2ac6xo 22 | rP4hQIPRdnzotDPtK/81BA4ZuHHh2bkvEkEq3m/3KRQG3qIigYOwHWPcFFHef2Pj 23 | vDJ/ah+/oAYTiH52H+zThUn9FfjeBfSJDpwsbAz34PQVhdFvahcuKEEeRolsUWTS 24 | pXS0F0aecae+2uC0UUPSXSmQ11tgddBwmpTb3VEjXGdw0q+4ZCN25L6Oir/fmmSs 25 | 7Vqw9lkWKsSSpKPAsydHUJHZFAWdjEEQcGq4wb9sY8hWk8sQAvrISNZtNTikjzZr 26 | hf42E+j5DTaAjNu2oMStzydVzCE5bhpZ+0rPcKdghA+6etNPtt+LwxzYpSrrlo7E 27 | nCW2u6ZUm6JXON2u/INhoGQIXX1XWuDObfn2/5XwcC1lcYvgXiUJhtSzMQEwPi6H 28 | o10MR/UJTafCwx5Fj5bkecYvbYkcwRNXi3W5cpSCLg== 29 | -----END CERTIFICATE----- 30 | -------------------------------------------------------------------------------- /tests/src/test/resources/certificates/trusted-servers.jks: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/grpc-ecosystem/grpc-spring/b83afe68cef63edc7dfeec694bc279956bbc8c3d/tests/src/test/resources/certificates/trusted-servers.jks -------------------------------------------------------------------------------- /tests/src/test/resources/certificates/trusted-servers.p12: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/grpc-ecosystem/grpc-spring/b83afe68cef63edc7dfeec694bc279956bbc8c3d/tests/src/test/resources/certificates/trusted-servers.p12 -------------------------------------------------------------------------------- /tests/src/test/resources/logback-test.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | %highlight(%d{HH:mm:ss.SSS} [%10thread] %-5level %logger{36} - %msg%n) 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | --------------------------------------------------------------------------------