@@ -13,6 +13,7 @@ This section describes how you can configure your grpc-spring-boot-starter clien
13
13
- [ ClientInterceptor] ( #clientinterceptor )
14
14
- [ StubFactory] ( #stubfactory )
15
15
- [ StubTransformer] ( #stubtransformer )
16
+ - [ Custom NameResolverProvider] ( #custom-nameresolverprovider )
16
17
17
18
## Additional Topics <!-- omit in toc -->
18
19
@@ -80,7 +81,8 @@ There are a number of supported schemes, that you can use to determine the targe
80
81
You can define custom
81
82
[ ` NameResolverProvider ` s] ( https://javadoc.io/page/io.grpc/grpc-all/latest/io/grpc/NameResolverProvider.html ) those
82
83
will be picked up, by either via Java's ` ServiceLoader ` or from spring's application context and registered in
83
- the ` NameResolverRegistry ` .
84
+ the ` NameResolverRegistry ` . \
85
+ See also [ Custom NameResolverProvider] ( #custom-nameresolverprovider )
84
86
85
87
If you don't define an address it will be guessed:
86
88
@@ -243,6 +245,23 @@ You can also use `StubTransformer`s to add custom `ClientInterceptor`s to your s
243
245
244
246
> ** Note** : The ` StubTransformer ` s are applied after the ` @GrpcClient#interceptors(Names) ` have been added.
245
247
248
+ ## Custom NameResolverProvider
249
+
250
+ Sometimes you might have some custom logic that decides which server you wish to connect to, you can achieve this
251
+ using a custom ` NameResolverProvider ` .
252
+
253
+ > ** Note:** This can only be used to decide this on an application level and not on a per request level.
254
+
255
+ This library provides some ` NameResolverProvider ` s itself so you can use them as a
256
+ [ reference] ( https://github.com/yidongnan/grpc-spring-boot-starter/tree/master/grpc-client-spring-boot-autoconfigure/src/main/java/net/devh/boot/grpc/client/nameresolver ) .
257
+
258
+ You can register your ` NameResolverProvider ` by adding it to ` META-INF/services/io.grpc.NameResolverProvider ` for Java's
259
+ ` ServiceLoader ` or adding it your spring context. If you wish to use some spring beans inside your ` NameResolver ` , then
260
+ you have to define it via spring context (unless you wish to use ` static ` ).
261
+
262
+ > ** Note:** ` NameResolverProvider ` s are registered gloablly, so might run into issues if you boot up two or more
263
+ > applications simulataneosly in the same JVM (e.g. during tests).
264
+
246
265
## Additional Topics <!-- omit in toc -->
247
266
248
267
- [ Getting Started] ( getting-started.md )
0 commit comments