Skip to content

Commit 9ca02dc

Browse files
committed
Merge branch 'master' into support_unix_domain_sockets_in_server
2 parents 32f1e72 + ed6a0e5 commit 9ca02dc

File tree

293 files changed

+5281
-1179
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

293 files changed

+5281
-1179
lines changed

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2016-2020 Michael Zhang <[email protected]>
3+
Copyright (c) 2016-2021 Michael Zhang <[email protected]>
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README-zh-CN.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ QQ交流群:294712648
3737

3838
2.x.x.RELEASE 支持 Spring Boot 2.1.x/2.2.x 和 Spring Cloud Greenwich / Hoxton。
3939

40-
最新版本: `2.10.1.RELEASE`
40+
最新版本: `2.12.0.RELEASE`
4141

4242
( `2.4.0.RELEASE` 用于 Spring Boot 2.0.x & Spring Cloud Finchy).
4343

@@ -57,15 +57,15 @@ QQ交流群:294712648
5757
<dependency>
5858
<groupId>net.devh</groupId>
5959
<artifactId>grpc-spring-boot-starter</artifactId>
60-
<version>2.10.1.RELEASE</version>
60+
<version>2.12.0.RELEASE</version>
6161
</dependency>
6262
````
6363

6464
Gradle:
6565

6666
````gradle
6767
dependencies {
68-
compile 'net.devh:grpc-spring-boot-starter:2.10.1.RELEASE'
68+
compile 'net.devh:grpc-spring-boot-starter:2.12.0.RELEASE'
6969
}
7070
````
7171

@@ -77,15 +77,15 @@ dependencies {
7777
<dependency>
7878
<groupId>net.devh</groupId>
7979
<artifactId>grpc-server-spring-boot-starter</artifactId>
80-
<version>2.10.1.RELEASE</version>
80+
<version>2.12.0.RELEASE</version>
8181
</dependency>
8282
````
8383

8484
Gradle:
8585

8686
````gradle
8787
dependencies {
88-
compile 'net.devh:grpc-server-spring-boot-starter:2.10.1.RELEASE'
88+
compile 'net.devh:grpc-server-spring-boot-starter:2.12.0.RELEASE'
8989
}
9090
````
9191

@@ -117,15 +117,15 @@ public class GrpcServerService extends GreeterGrpc.GreeterImplBase {
117117
<dependency>
118118
<groupId>net.devh</groupId>
119119
<artifactId>grpc-client-spring-boot-starter</artifactId>
120-
<version>2.10.1.RELEASE</version>
120+
<version>2.12.0.RELEASE</version>
121121
</dependency>
122122
````
123123

124124
Gradle:
125125

126126
````gradle
127127
dependencies {
128-
compile 'net.devh:grpc-client-spring-boot-starter:2.10.1.RELEASE'
128+
compile 'net.devh:grpc-client-spring-boot-starter:2.12.0.RELEASE'
129129
}
130130
````
131131
在 grpc 客户端的的 stub 字段上添加 `@GrpcClient(serverName)` 注解。

README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ README: [English](README.md) | [中文](README-zh-CN.md)
5252

5353
2.x.x.RELEASE supports Spring Boot 2.1.x/2.2.x & Spring Cloud Greenwich/Hoxton.
5454

55-
The latest version: ``2.10.1.RELEASE``
55+
The latest version: ``2.12.0.RELEASE``
5656

5757
(Use `2.4.0.RELEASE` for Spring Boot 2.0.x & Spring Cloud Finchley).
5858

@@ -72,15 +72,15 @@ To add a dependency using Maven, use the following:
7272
<dependency>
7373
<groupId>net.devh</groupId>
7474
<artifactId>grpc-spring-boot-starter</artifactId>
75-
<version>2.10.1.RELEASE</version>
75+
<version>2.12.0.RELEASE</version>
7676
</dependency>
7777
````
7878

7979
To add a dependency using Gradle:
8080

8181
````gradle
8282
dependencies {
83-
implementation 'net.devh:grpc-spring-boot-starter:2.10.1.RELEASE'
83+
implementation 'net.devh:grpc-spring-boot-starter:2.12.0.RELEASE'
8484
}
8585
````
8686

@@ -92,15 +92,15 @@ To add a dependency using Maven, use the following:
9292
<dependency>
9393
<groupId>net.devh</groupId>
9494
<artifactId>grpc-server-spring-boot-starter</artifactId>
95-
<version>2.10.1.RELEASE</version>
95+
<version>2.12.0.RELEASE</version>
9696
</dependency>
9797
````
9898

9999
To add a dependency using Gradle:
100100

101101
````gradle
102102
dependencies {
103-
implementation 'net.devh:grpc-server-spring-boot-starter:2.10.1.RELEASE'
103+
implementation 'net.devh:grpc-server-spring-boot-starter:2.12.0.RELEASE'
104104
}
105105
````
106106

@@ -134,15 +134,15 @@ To add a dependency using Maven, use the following:
134134
<dependency>
135135
<groupId>net.devh</groupId>
136136
<artifactId>grpc-client-spring-boot-starter</artifactId>
137-
<version>2.10.1.RELEASE</version>
137+
<version>2.12.0.RELEASE</version>
138138
</dependency>
139139
````
140140

141141
To add a dependency using Gradle:
142142

143143
````gradle
144144
dependencies {
145-
compile 'net.devh:grpc-client-spring-boot-starter:2.10.1.RELEASE'
145+
compile 'net.devh:grpc-client-spring-boot-starter:2.12.0.RELEASE'
146146
}
147147
````
148148

build.gradle

Lines changed: 41 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,25 @@ buildscript {
99
}
1010
}
1111
ext {
12-
projectVersion = '2.11.0-SNAPSHOT'
12+
projectVersion = '2.13.0-SNAPSHOT'
1313

1414
// https://github.com/grpc/grpc-java/releases
15-
grpcVersion = '1.32.2'
15+
grpcVersion = '1.37.0'
16+
17+
// https://github.com/google/guava/releases
18+
guavaVersion = '30.1.1-jre'
1619
// https://github.com/protocolbuffers/protobuf/releases
17-
protobufVersion = '3.13.0'
20+
protobufVersion = '3.15.8'
1821
protobufGradlePluginVersion = '0.8.12'
1922

2023
// https://github.com/spring-projects/spring-boot/releases
21-
springBootVersion = '2.3.4.RELEASE'
24+
springBootVersion = '2.4.5'
2225
// https://github.com/spring-cloud/spring-cloud-release/releases
23-
springCloudVersion = 'Hoxton.SR8'
26+
springCloudVersion = '2020.0.2'
2427
// https://github.com/alibaba/spring-cloud-alibaba/releases
25-
springCloudAlibabaNacosVersion = '2.2.3.RELEASE'
28+
springCloudAlibabaNacosVersion = '2021.1'
2629
// https://github.com/spring-projects/spring-security-oauth/releases
27-
springSecurityOAuthVersion = '2.5.0.RELEASE'
30+
springSecurityOAuthVersion = '2.5.1.RELEASE'
2831

2932
lombokPluginVersion = '4.0.0'
3033
versioningPluginVersion = '2.14.0'
@@ -35,14 +38,13 @@ buildscript {
3538
plugins {
3639
id 'java'
3740
id 'java-library'
38-
// future improvement would be to use the version declared above in the ext block instead of repeating it here
39-
id 'org.springframework.boot' version '2.3.4.RELEASE' apply false
40-
id 'io.spring.dependency-management' version '1.0.10.RELEASE'
41+
id 'org.springframework.boot' version "${springBootVersion}" apply false
42+
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
4143
id 'net.nemerosa.versioning' version '2.14.0'
42-
id 'com.google.protobuf' version '0.8.13'
44+
id 'com.google.protobuf' version '0.8.15'
4345
id 'io.franzbecker.gradle-lombok' version '4.0.0' apply false
44-
id 'com.github.ben-manes.versions' version '0.33.0' // gradle dependencyUpdates
45-
id 'com.diffplug.spotless' version '5.7.0'
46+
id 'com.github.ben-manes.versions' version '0.36.0' // gradle dependencyUpdates
47+
id 'com.diffplug.spotless' version '5.11.0'
4648
}
4749

4850
// If you attempt to build without the `--scan` parameter in `gradle 6.0+` it will cause a build error that it can't find
@@ -58,7 +60,7 @@ if (hasProperty('buildScan')) {
5860
wrapper {
5961
// Update using:
6062
// ./gradlew wrapper --gradle-version=6.5 --distribution-type=bin
61-
gradleVersion = '6.7'
63+
gradleVersion = '7.0'
6264
}
6365

6466
def buildTimeAndDate = OffsetDateTime.now()
@@ -77,6 +79,12 @@ allprojects {
7779
apply plugin: 'com.diffplug.spotless'
7880
apply plugin: 'io.franzbecker.gradle-lombok'
7981

82+
java {
83+
toolchain {
84+
languageVersion = JavaLanguageVersion.of(8)
85+
}
86+
}
87+
8088
compileJava {
8189
sourceCompatibility = JavaVersion.VERSION_1_8
8290
targetCompatibility = JavaVersion.VERSION_1_8
@@ -87,6 +95,13 @@ allprojects {
8795
'-Xlint:all', '-Xlint:-processing'
8896
]
8997

98+
eclipse {
99+
classpath {
100+
downloadJavadoc = true
101+
downloadSources = true
102+
}
103+
}
104+
90105
spotless {
91106
java {
92107
licenseHeaderFile rootProject.file('extra/spotless/mit-license.java')
@@ -96,11 +111,20 @@ allprojects {
96111
}
97112
format('misc') {
98113
target('**/*.gradle', '**/*.md', '**/*.yml')
114+
targetExclude('**/build/**/*.*')
99115
trimTrailingWhitespace()
100116
endWithNewline()
101117
}
102118
}
103119

120+
normalization {
121+
runtimeClasspath {
122+
metaInf{
123+
ignoreAttribute('Build-Time')
124+
}
125+
}
126+
}
127+
104128
// Copy LICENSE
105129
tasks.withType(Jar) {
106130
from(project.rootDir) {
@@ -131,7 +155,6 @@ allprojects {
131155

132156
repositories {
133157
mavenCentral()
134-
jcenter()
135158
}
136159

137160
buildscript {
@@ -156,8 +179,11 @@ allprojects { project ->
156179
imports {
157180
mavenBom "org.springframework.boot:spring-boot-starter-parent:${springBootVersion}"
158181
mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
182+
mavenBom "com.alibaba.cloud:spring-cloud-alibaba-dependencies:${springCloudAlibabaNacosVersion}"
159183
mavenBom "com.google.protobuf:protobuf-bom:${protobufVersion}"
184+
mavenBom "com.google.guava:guava-bom:${guavaVersion}"
160185
mavenBom "io.grpc:grpc-bom:${grpcVersion}"
186+
mavenBom "org.junit:junit-bom:5.7.0"
161187
}
162188
}
163189

docs/en/client/configuration.md

Lines changed: 68 additions & 2 deletions
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

@@ -64,7 +65,7 @@ There are a number of supported schemes, that you can use to determine the targe
6465
one and also supports `SVC` lookups. See also [Kubernetes Setup](../kubernetes.md).
6566
- `discovery` (Prio 6): \
6667
(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
68+
automatically during `HeartbeatEvent`s. Uses the `gRPC_port` metadata to determine the port, otherwise uses the
6869
service port. \
6970
Example: `discovery:///service-name`
7071
- `self` (Prio 0): \
@@ -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

@@ -128,13 +130,60 @@ public GrpcChannelConfigurer keepAliveClientConfigurer() {
128130
129131
### ClientInterceptor
130132

133+
`ClientInterceptor`s can be used for various tasks, including:
134+
135+
- Authentication/Authorization
136+
- Request validation
137+
- Response filtering
138+
- Attaching additional context to the call (e.g. tracing ids)
139+
- Exception to error `Status` response mapping
140+
- Logging
141+
- ...
142+
131143
There are three ways to add a `ClientInterceptor` to your channel.
132144

133145
- Define the `ClientInterceptor` as a global interceptor using either the `@GrpcGlobalClientInterceptor` annotation,
134146
or a `GlobalClientInterceptorConfigurer`
135147
- Explicitly list them in the `@GrpcClient#interceptors` or `@GrpcClient#interceptorNames` field
136148
- Use a `StubTransformer` and call `stub.withInterceptors(ClientInterceptor... interceptors)`
137149

150+
The following examples demonstrate how to use annotations to create a global client interceptor:
151+
152+
````java
153+
@Configuration
154+
public class ThirdPartyInterceptorConfig {}
155+
156+
@GrpcGlobalServerInterceptor
157+
LogGrpcInterceptor logServerInterceptor() {
158+
return new LogGrpcInterceptor();
159+
}
160+
161+
}
162+
````
163+
164+
This variant is very handy if you wish to add third-party interceptors to the global scope.
165+
166+
For your own interceptor implementations you can achieve the same result by adding the annotation to the class itself:
167+
168+
````java
169+
@GrpcGlobalServerInterceptor
170+
public class LogGrpcInterceptor implements ServerInterceptor {
171+
172+
private static final Logger log = LoggerFactory.getLogger(LogGrpcInterceptor.class);
173+
174+
@Override
175+
public <ReqT, RespT> ServerCall.Listener<ReqT> interceptCall(
176+
ServerCall<ReqT, RespT> serverCall,
177+
Metadata metadata,
178+
ServerCallHandler<ReqT, RespT> serverCallHandler) {
179+
180+
log.info(serverCall.getMethodDescriptor().getFullMethodName());
181+
return serverCallHandler.startCall(serverCall, metadata);
182+
}
183+
184+
}
185+
````
186+
138187
### StubFactory
139188

140189
A `StubFactory` is used to create a `Stub` of a specific type. The registered stub factories will be checked in order
@@ -196,6 +245,23 @@ You can also use `StubTransformer`s to add custom `ClientInterceptor`s to your s
196245

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

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

0 commit comments

Comments
 (0)