Skip to content

Commit 96f1096

Browse files
committed
Change metadata from gRPC.port to gRPC_port, and configure in metadata instead tag. This lis does not read tags, only metadata.
1 parent 496971b commit 96f1096

File tree

6 files changed

+16
-16
lines changed

6 files changed

+16
-16
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ buildscript {
99
}
1010
}
1111
ext {
12-
projectVersion = '2.11.0-SNAPSHOT'
12+
projectVersion = '2.11.1-SNAPSHOT'
1313

1414
// https://github.com/grpc/grpc-java/releases
1515
grpcVersion = '1.35.0'

docs/en/client/configuration.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ There are a number of supported schemes, that you can use to determine the targe
6464
one and also supports `SVC` lookups. See also [Kubernetes Setup](../kubernetes.md).
6565
- `discovery` (Prio 6): \
6666
(Optional) Uses spring-cloud's `DiscoveryClient` to lookup appropriate targets. The connections will be refreshed
67-
automatically during `HeartbeatEvent`s. Uses the `gRPC.port` metadata to determine the port, otherwise uses the
67+
automatically during `HeartbeatEvent`s. Uses the `gRPC_port` metadata to determine the port, otherwise uses the
6868
service port. \
6969
Example: `discovery:///service-name`
7070
- `self` (Prio 0): \

docs/zh-CN/client/configuration.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ grpc.client.__name__.address=static://localhost:9090
4444

4545
- `static`(优先级 4): 一个简单的IP静态列表 (v4 和 v6), 可用于连接到服务端 (支持 `localhost`)。 例如:`static://192.168.1:8080,10.0.0.1:1337`
4646
- [`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`
47-
- `discovery` (优先级 6):(可选) 使用 Spring Cloud 的`DiscoveryClient` 去查找合适的目标。 在 `HeartbeatEvent` 的时候,连接将自动刷新。 使用 `gRPC.port` 元数据来确定端口,否则使用服务端口。 示例: `discovery:///service-name`
47+
- `discovery` (优先级 6):(可选) 使用 Spring Cloud 的`DiscoveryClient` 去查找合适的目标。 在 `HeartbeatEvent` 的时候,连接将自动刷新。 使用 `gRPC_port` 元数据来确定端口,否则使用服务端口。 示例: `discovery:///service-name`
4848
- `self`(优先级 0):如果您使用 `grpc-server-spring-boot-starter` 并且不想指定自己的地址 / 端口,则可以使用 self 关键词作为 scheme 或者 address 。 这对于需要使用随机服务器端口以避免冲突的测试特别有用。 例如:`self``self:self`
4949
- `in-process`:这是一个特殊的方案,将使用 `InProcessChannelFactory` 来替代原有正常的 ChannelFactory。 并使用它连接到 [`InProcessServer`](../server/configuration.md#enabling-the-inprocessserver)。 例如:`in-process:foobar`
5050
- *custom*: 您可以通过 Java 的 `ServiceLoader` 或从 Spring 的应用上下文中选择要自定义的 [`NameResolverProvider`](https://javadoc.io/page/io.grpc/grpc-all/latest/io/grpc/NameResolverProvider.html) ,并将其注册到 `NameResolverRegistry` 上.

grpc-client-spring-boot-autoconfigure/src/main/java/net/devh/boot/grpc/client/nameresolver/DiscoveryClientNameResolver.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444

4545
/**
4646
* The DiscoveryClientNameResolver resolves the service hosts and their associated gRPC port using the channel's name
47-
* and spring's cloud {@link DiscoveryClient}. The ports are extracted from the {@code gRPC.port} metadata.
47+
* and spring's cloud {@link DiscoveryClient}. The ports are extracted from the {@code gRPC_port} metadata.
4848
*
4949
* @author Michael ([email protected])
5050
* @author Daniel Theuke ([email protected])

grpc-common-spring-boot/src/main/java/net/devh/boot/grpc/common/util/GrpcUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public final class GrpcUtils {
2929
/**
3030
* The cloud discovery metadata key used to identify the grpc port.
3131
*/
32-
public static final String CLOUD_DISCOVERY_METADATA_PORT = "gRPC.port";
32+
public static final String CLOUD_DISCOVERY_METADATA_PORT = "gRPC_port";
3333

3434
/**
3535
* The constant for the grpc server port, -1 represents don't start an inter process server.

grpc-server-spring-boot-autoconfigure/src/main/java/net/devh/boot/grpc/server/autoconfigure/GrpcMetadataConsulConfiguration.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,17 @@
1717

1818
package net.devh.boot.grpc.server.autoconfigure;
1919

20-
import java.util.ArrayList;
21-
import java.util.List;
22-
23-
import javax.annotation.PostConstruct;
24-
20+
import net.devh.boot.grpc.common.util.GrpcUtils;
21+
import net.devh.boot.grpc.server.config.GrpcServerProperties;
2522
import org.springframework.beans.factory.annotation.Autowired;
2623
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
2724
import org.springframework.boot.context.properties.EnableConfigurationProperties;
2825
import org.springframework.cloud.consul.serviceregistry.ConsulRegistration;
2926
import org.springframework.context.annotation.Configuration;
3027

31-
import net.devh.boot.grpc.common.util.GrpcUtils;
32-
import net.devh.boot.grpc.server.config.GrpcServerProperties;
28+
import javax.annotation.PostConstruct;
29+
import java.util.HashMap;
30+
import java.util.Map;
3331

3432
/**
3533
* Configuration class that configures the required beans for gRPC discovery via Consul.
@@ -52,11 +50,13 @@ public class GrpcMetadataConsulConfiguration {
5250
public void init() {
5351
if (consulRegistration != null) {
5452
final int port = grpcProperties.getPort();
55-
List<String> tags = consulRegistration.getService().getTags();
56-
tags = tags == null ? new ArrayList<>() : tags;
53+
Map<String, String> meta = consulRegistration.getService().getMeta();
54+
if (meta == null) {
55+
meta = new HashMap<>();
56+
}
5757
if (GrpcUtils.INTER_PROCESS_DISABLE != port) {
58-
tags.add(GrpcUtils.CLOUD_DISCOVERY_METADATA_PORT + "=" + port);
59-
consulRegistration.getService().setTags(tags);
58+
meta.put(GrpcUtils.CLOUD_DISCOVERY_METADATA_PORT, Integer.toString(port));
59+
consulRegistration.getService().setMeta(meta);
6060
}
6161
}
6262
}

0 commit comments

Comments
 (0)