Skip to content

Commit d2d50ed

Browse files
authored
Merge pull request #525 from yidongnan/docs/custom-name-resolver
Add Custom NameResolverProvider section to the docs
2 parents 5573e74 + f21a2d9 commit d2d50ed

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

docs/en/client/configuration.md

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ This section describes how you can configure your grpc-spring-boot-starter clien
1313
- [ClientInterceptor](#clientinterceptor)
1414
- [StubFactory](#stubfactory)
1515
- [StubTransformer](#stubtransformer)
16+
- [Custom NameResolverProvider](#custom-nameresolverprovider)
1617

1718
## Additional Topics <!-- omit in toc -->
1819

@@ -80,7 +81,8 @@ There are a number of supported schemes, that you can use to determine the targe
8081
You can define custom
8182
[`NameResolverProvider`s](https://javadoc.io/page/io.grpc/grpc-all/latest/io/grpc/NameResolverProvider.html) those
8283
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)
8486

8587
If you don't define an address it will be guessed:
8688

@@ -243,6 +245,23 @@ You can also use `StubTransformer`s to add custom `ClientInterceptor`s to your s
243245

244246
> **Note**: The `StubTransformer`s are applied after the `@GrpcClient#interceptors(Names)` have been added.
245247
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+
246265
## Additional Topics <!-- omit in toc -->
247266

248267
- [Getting Started](getting-started.md)

0 commit comments

Comments
 (0)