diff --git a/spring-grpc-docs/src/main/antora/modules/ROOT/pages/client.adoc b/spring-grpc-docs/src/main/antora/modules/ROOT/pages/client.adoc index fa9e84d..a46c85b 100644 --- a/spring-grpc-docs/src/main/antora/modules/ROOT/pages/client.adoc +++ b/spring-grpc-docs/src/main/antora/modules/ROOT/pages/client.adoc @@ -39,7 +39,7 @@ The `@ImportGrpcClients` annotation can be used to control the scan for gRPC stu To scan a package you can specify the `basePackages` or `basePackageClasses` attribute. Then elsewhere in the application you can `@Autowired` the generated gRPC stubs (the blocking sub-type by default). You can change the factory used to create the stubs from `BlockingStubFactory` by setting the `factory` attribute. -There are standard factories pre-registered for common stub types, and if you want to register additional factories you can use a `GrpcClientFactoryCustomizer` (see below for details). +There are standard factories pre-registered for common stub types, and if you want to register additional factories you can add a bean of type `StubFactory` (see below for details). The default behaviour in a Spring Boot application is equivalent to the following configuration on your `@SpringBootApplication` class: @@ -53,37 +53,31 @@ class MyApplication { } ---- -You can enhance and modify the configuration by providing `spring.grpc.client.*` application properties or by defining your own `GrpcClientFactoryCustomizer` beans. -The customizer has full control over the scanning and registration of the gRPC clients, including for example the ability to change the base type of the stubs that are registered. +You can enhance and modify the configuration by providing `spring.grpc.client.*` application properties or by defining your own `GrpcChannelBuilderCustomizer` beans. === More Complex Examples -A `GrpcClientFactoryCustomizer` can also control the creation of the channels and add custom behaviour to stubs (individually or via a scan). +A `GrpcChannelBuilderCustomizer` can also control the creation of the channels and add custom behaviour to stubs (individually or via a scan). For example, to add a custom security interceptor to only clients using the "stub" channel: [source,java] ---- -@ImportGrpcClients(basePackageClasses = MyApplication.class) +@ImportGrpcClients(target = "stub", prefix = "secure", types = SimpleBlockingStub.class) @Configuration class ExtraConfiguration { @Bean - GrpcClientFactoryCustomizer stubs() { - return registry -> registry - .channel("stub", - ChannelBuilderOptions.defaults() - .withInterceptors(List.of(new BearerTokenAuthenticationInterceptor(() -> token(context))))); + GrpcChannelBuilderCustomizer stubs() { + return GrpcChannelBuilderCustomizer.matches("stub", builder -> + builder.intercept(new BearerTokenAuthenticationInterceptor(() -> token(context)))); } } ---- -In this example, instead of scanning for all stubs, we register a specific stub class `SimpleGrpc.SimpleBlockingStub` with the channel named `stub`. +In this example, instead of scanning for all stubs, we register a specific stub class `SimpleBlockingStub` with the channel named `stub`. The prefix `secure` is used as a bean definition name prefix, so the resulting bean definition in this case is "secureSimpleBlockingStub". This feature is useful when you want to have multiple instances of the same stub class with different configurations. -The configuration of the individual client specs is done completely separately from the channel factory configuration. -This is an important distinction because, although they might be related, the two things happen at very different times in the application lifecycle. -In particular it is futile to try to inject other beans into `MyClientRegistrar` because the beans are not available yet - its role is to define a set of bean definitions to be created later. == Create a Client Manually @@ -209,7 +203,7 @@ For example: spring.grpc.client.channels.local.address=0.0.0.0:${local.grpc.port} ---- -You can't use `@LocalGrpcPort` in a `GrpcClientFactoryCustomizer` because it is not available until the server starts. +You can't use `@LocalGrpcPort` in a bean that creates a stub, unless it is marked `@Lazy`, because it is not available until the server starts. You can lazily resolve `local.grpc.port` in the customizer by using the `Environment` when the channel is created, either directly via its API or through placeholders like in the properties file example above. [[client-interceptor]] diff --git a/spring-grpc-docs/src/main/antora/modules/ROOT/pages/whats-new.adoc b/spring-grpc-docs/src/main/antora/modules/ROOT/pages/whats-new.adoc index f42fa5f..8ffb2f2 100644 --- a/spring-grpc-docs/src/main/antora/modules/ROOT/pages/whats-new.adoc +++ b/spring-grpc-docs/src/main/antora/modules/ROOT/pages/whats-new.adoc @@ -2,6 +2,15 @@ :page-section-summary-toc: 1 +[[what-s-new-in-0-9-0-since-0-8-0]] +== What's New in 0.9.0 Since 0.8.0 + +This section covers the changes made from version 0.8.0 to version 0.9.0. + +* Upgrade to Spring Boot 3.5.0. +* `StubFactory` contract changes: the "supports" method is now a static method (it is called before an instance is created). +* Removed `GrpcClientFactoryCustomizer` in favour of `GrpcChannelBuilderCustomizer`. + [[what-s-new-in-0-6-0-since-0-5-0]] == What's New in 0.6.0 Since 0.5.0