diff --git a/build.gradle b/build.gradle index d14bd3677..85fcf7715 100644 --- a/build.gradle +++ b/build.gradle @@ -12,7 +12,7 @@ buildscript { projectVersion = '2.13.0-SNAPSHOT' // https://github.com/grpc/grpc-java/releases - grpcVersion = '1.37.0' + grpcVersion = '1.40.1' // https://github.com/google/guava/releases guavaVersion = '30.1.1-jre' diff --git a/docs/en/client/configuration.md b/docs/en/client/configuration.md index acfa90ed8..c0d116dbc 100644 --- a/docs/en/client/configuration.md +++ b/docs/en/client/configuration.md @@ -75,7 +75,7 @@ There are a number of supported schemes, that you can use to determine the targe The self address or scheme is a keyword that is available, if you also use `grpc-server-spring-boot-starter` and allows you to connect to the server without specifying the own address/port. This is especially useful for tests where you might want to use random server ports to avoid conflicts. \ - Example: `self` or `self:self` + Example: `self:self` - `in-process`: \ This is a special scheme that will bypass the normal channel factory and will use the `InProcessChannelFactory` instead. Use it to connect to the [`InProcessServer`](../server/configuration.md#enabling-the-inprocessserver). \ diff --git a/docs/zh-CN/client/configuration.md b/docs/zh-CN/client/configuration.md index 673588e2c..516c6e528 100644 --- a/docs/zh-CN/client/configuration.md +++ b/docs/zh-CN/client/configuration.md @@ -45,7 +45,7 @@ grpc.client.__name__.address=static://localhost:9090 - `static`(优先级 4): 一个简单的IP静态列表 (v4 和 v6), 可用于连接到服务端 (支持 `localhost`)。 例如:`static://192.168.1:8080,10.0.0.1:1337` - [`dns`](https://github.com/grpc/grpc-java/blob/master/core/src/main/java/io/grpc/internal/DnsNameResolver.java#L66)(优先级 5):解析并绑定到给定 DNS 名称的所有地址。 地址将被缓存,只有当现有连接被关闭 / 失败时才会刷新。 更多选项,例如 `SVC` 查找(对 kubernetes 有用),可以通过系统属性启用。 例如:`dns:///example.my.company` - `discovery` (优先级 6):(可选) 使用 Spring Cloud 的`DiscoveryClient` 去查找合适的目标。 在 `HeartbeatEvent` 的时候,连接将自动刷新。 使用 `gRPC_port` 元数据来确定端口,否则使用服务端口。 示例: `discovery:///service-name` -- `self`(优先级 0):如果您使用 `grpc-server-spring-boot-starter` 并且不想指定自己的地址 / 端口,则可以使用 self 关键词作为 scheme 或者 address 。 这对于需要使用随机服务器端口以避免冲突的测试特别有用。 例如:`self`或`self:self` +- `self`(优先级 0):如果您使用 `grpc-server-spring-boot-starter` 并且不想指定自己的地址 / 端口,则可以使用 self 关键词作为 scheme 或者 address 。 这对于需要使用随机服务器端口以避免冲突的测试特别有用。 例如:`self:self` - `in-process`:这是一个特殊的方案,将使用 `InProcessChannelFactory` 来替代原有正常的 ChannelFactory。 并使用它连接到 [`InProcessServer`](../server/configuration.md#enabling-the-inprocessserver)。 例如:`in-process:foobar` - *custom*: 您可以通过 Java 的 `ServiceLoader` 或从 Spring 的应用上下文中选择要自定义的 [`NameResolverProvider`](https://javadoc.io/page/io.grpc/grpc-all/latest/io/grpc/NameResolverProvider.html) ,并将其注册到 `NameResolverRegistry` 上. diff --git a/grpc-server-spring-boot-autoconfigure/src/main/java/net/devh/boot/grpc/server/nameresolver/SelfNameResolverFactory.java b/grpc-server-spring-boot-autoconfigure/src/main/java/net/devh/boot/grpc/server/nameresolver/SelfNameResolverFactory.java index 5e118711d..a9cf6c7e6 100644 --- a/grpc-server-spring-boot-autoconfigure/src/main/java/net/devh/boot/grpc/server/nameresolver/SelfNameResolverFactory.java +++ b/grpc-server-spring-boot-autoconfigure/src/main/java/net/devh/boot/grpc/server/nameresolver/SelfNameResolverFactory.java @@ -50,7 +50,7 @@ public SelfNameResolverFactory(final GrpcServerProperties properties) { @Override public NameResolver newNameResolver(final URI targetUri, final Args args) { - if (SELF_SCHEME.equals(targetUri.getScheme()) || targetUri.toString().equals(SELF_SCHEME)) { + if (SELF_SCHEME.equals(targetUri.getScheme())) { return new SelfNameResolver(this.properties, args); } return null; diff --git a/tests/src/test/java/net/devh/boot/grpc/test/setup/SelfNameResolverConnectionTest.java b/tests/src/test/java/net/devh/boot/grpc/test/setup/SelfNameResolverConnectionTest.java index 29ebee30f..78fa63138 100644 --- a/tests/src/test/java/net/devh/boot/grpc/test/setup/SelfNameResolverConnectionTest.java +++ b/tests/src/test/java/net/devh/boot/grpc/test/setup/SelfNameResolverConnectionTest.java @@ -40,7 +40,7 @@ @SpringBootTest(properties = { "grpc.server.port=0", "grpc.client.GLOBAL.negotiationType=PLAINTEXT", - "grpc.client.other.address=self", + "grpc.client.test.address=self:self", }) @SpringJUnitConfig(classes = {ServiceConfiguration.class, BaseAutoConfiguration.class}) @DirtiesContext @@ -48,12 +48,9 @@ public class SelfNameResolverConnectionTest { private static final Empty EMPTY = Empty.getDefaultInstance(); - @GrpcClient("self") + @GrpcClient("test") private TestServiceBlockingStub selfStub; - @GrpcClient("other") - private TestServiceBlockingStub otherStub; - /** * Tests the connection via the implicit client address. */ @@ -62,12 +59,4 @@ public void testSelfConnection() { assertEquals("1.2.3", this.selfStub.normal(EMPTY).getVersion()); } - /** - * Tests the connection via the explicit client address. - */ - @Test - public void testOtherConnection() { - assertEquals("1.2.3", this.otherStub.normal(EMPTY).getVersion()); - } - }