Skip to content

Commit f6e6278

Browse files
committed
Merge branch 'master' into pr/520
Conflicts: build.gradle gradle/wrapper/gradle-wrapper.properties
2 parents ea27bb6 + 4571dc0 commit f6e6278

File tree

54 files changed

+2439
-697
lines changed

Some content is hidden

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

54 files changed

+2439
-697
lines changed

README.md

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,9 @@ README: [English](README.md) | [中文](README-zh-CN.md)
5050

5151
## Versions
5252

53-
2.x.x.RELEASE supports Spring Boot 2.1.x/2.2.x & Spring Cloud Greenwich/Hoxton.
54-
55-
The latest version: ``2.12.0.RELEASE``
56-
57-
(Use `2.4.0.RELEASE` for Spring Boot 2.0.x & Spring Cloud Finchley).
58-
59-
1.x.x.RELEASE support Spring Boot 1 & Spring Cloud Edgware, Dalston, Camden.
60-
61-
The latest version: ``1.4.2.RELEASE``
53+
The latest version is `2.12.0.RELEASE` it was compiled with spring-boot `2.4.5` and spring-cloud `2020.0.2`
54+
but it is also compatible with a large variety of other versions.
55+
An overview of all versions and their respective library versions can be found in our [documentation](https://yidongnan.github.io/grpc-spring-boot-starter/en/versions.html).
6256

6357
**Note:** This project can also be used without Spring-Boot, however that requires some manual bean configuration.
6458

build.gradle

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,26 +11,26 @@ buildscript {
1111
projectVersion = '2.13.0-SNAPSHOT'
1212

1313
// https://github.com/grpc/grpc-java/releases
14-
grpcVersion = '1.37.0'
14+
grpcVersion = '1.42.1'
1515

1616
// https://github.com/google/guava/releases
17-
guavaVersion = '30.1.1-jre'
17+
guavaVersion = '31.0.1-jre'
1818
// https://github.com/protocolbuffers/protobuf/releases
19-
protobufVersion = '3.15.8'
20-
protobufGradlePluginVersion = '0.8.12'
19+
protobufVersion = '3.19.1'
20+
protobufGradlePluginVersion = '0.8.18'
2121

2222
// https://github.com/spring-projects/spring-boot/releases
23-
springBootVersion = '2.4.5'
23+
springBootVersion = '2.5.6'
2424
// https://github.com/spring-cloud/spring-cloud-release/releases
25-
springCloudVersion = '2020.0.2'
25+
springCloudVersion = '2020.0.4'
2626
// https://github.com/alibaba/spring-cloud-alibaba/releases
2727
springCloudAlibabaNacosVersion = '2021.1'
2828
// https://github.com/spring-projects/spring-security-oauth/releases
2929
springSecurityOAuthVersion = '2.5.1.RELEASE'
3030

31-
lombokPluginVersion = '5.3.3.3'
32-
versioningPluginVersion = '2.14.0'
33-
versionsPluginVersion = '0.29.0'
31+
lombokPluginVersion = '6.3.0'
32+
versioningPluginVersion = '2.15.1'
33+
versionsPluginVersion = '0.39.0'
3434
}
3535
}
3636

@@ -39,11 +39,11 @@ plugins {
3939
id 'java-library'
4040
id 'org.springframework.boot' version "${springBootVersion}" apply false
4141
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
42-
id 'net.nemerosa.versioning' version '2.14.0'
43-
id 'com.google.protobuf' version '0.8.15'
44-
id 'io.freefair.lombok' version '5.3.3.3' apply false
45-
id 'com.github.ben-manes.versions' version '0.36.0' // gradle dependencyUpdates
46-
id 'com.diffplug.spotless' version '5.12.1'
42+
id 'net.nemerosa.versioning' version "${versioningPluginVersion}"
43+
id 'com.google.protobuf' version "${protobufGradlePluginVersion}"
44+
id 'io.freefair.lombok' version "${lombokPluginVersion}" apply false
45+
id 'com.github.ben-manes.versions' version "${versionsPluginVersion}" // gradle dependencyUpdates
46+
id 'com.diffplug.spotless' version '6.0.0'
4747
}
4848

4949
// 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,8 +58,8 @@ if (hasProperty('buildScan')) {
5858
// you may use IntelliJ's project configuration to make it use the gradle version defined in the gradle script's wrapper section
5959
wrapper {
6060
// Update using:
61-
// ./gradlew wrapper --gradle-version=6.5 --distribution-type=bin
62-
gradleVersion = '7.0.1'
61+
// ./gradlew wrapper --gradle-version=7.3 --distribution-type=bin
62+
gradleVersion = '7.3'
6363
}
6464

6565
def buildTimeAndDate = OffsetDateTime.now()

docs/en/client/configuration.md

Lines changed: 83 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ This section describes how you can configure your grpc-spring-boot-starter clien
99
- [Configuration via Properties](#configuration-via-properties)
1010
- [Choosing the Target](#choosing-the-target)
1111
- [Configuration via Beans](#configuration-via-beans)
12+
- [GrpcClientBean](#grpcclientbean)
1213
- [GrpcChannelConfigurer](#grpcchannelconfigurer)
1314
- [ClientInterceptor](#clientinterceptor)
1415
- [StubFactory](#stubfactory)
@@ -38,9 +39,10 @@ If you prefer to read the sources instead, you can do so
3839
[here](https://github.com/yidongnan/grpc-spring-boot-starter/blob/master/grpc-client-spring-boot-autoconfigure/src/main/java/net/devh/boot/grpc/client/config/GrpcChannelProperties.java#L58).
3940

4041
The properties for the channels are all prefixed with `grpc.client.__name__.` and `grpc.client.__name__.security.`
41-
respectively. The channel name is taken from the `@GrpcClient` annotation. If you wish to configure some options such as
42-
trusted certificates for all servers at once you can do so using `GLOBAL` as name. Properties that are defined for a
43-
name channel take precedence over global once.
42+
respectively. The channel name is taken from the `@GrpcClient("__name__")` annotation.
43+
If you wish to configure some options such as trusted certificates for all servers at once,
44+
you can do so using `GLOBAL` as name.
45+
Properties that are defined for a specific/named channel take precedence over `GLOBAL` ones.
4446

4547
### Choosing the Target
4648

@@ -55,6 +57,7 @@ There are a number of supported schemes, that you can use to determine the targe
5557

5658
- `static` (Prio 4): \
5759
A simple static list of IPs (both v4 and v6), that can be use connect to the server (Supports `localhost`). \
60+
For resolvable hostnames please use `dns` instead. \
5861
Example: `static://192.168.1.1:8080,10.0.0.1:1337`
5962
- [`dns`](https://github.com/grpc/grpc-java/blob/master/core/src/main/java/io/grpc/internal/DnsNameResolver.java#L66)
6063
(Prio 5): \
@@ -72,11 +75,16 @@ There are a number of supported schemes, that you can use to determine the targe
7275
The self address or scheme is a keyword that is available, if you also use `grpc-server-spring-boot-starter` and
7376
allows you to connect to the server without specifying the own address/port. This is especially useful for tests
7477
where you might want to use random server ports to avoid conflicts. \
75-
Example: `self` or `self:self`
78+
Example: `self:self`
7679
- `in-process`: \
7780
This is a special scheme that will bypass the normal channel factory and will use the `InProcessChannelFactory`
7881
instead. Use it to connect to the [`InProcessServer`](../server/configuration.md#enabling-the-inprocessserver). \
7982
Example: `in-process:foobar`
83+
- `unix` (Available on Unix based systems only): \
84+
This is a special scheme that uses unix's domain socket addresses to connect to a server. \
85+
If you are using `grpc-netty` you also need the `netty-transport-native-epoll` dependency.
86+
`grpc-netty-shaded` already contains that dependency, so there is no need to add anything for it to work. \
87+
Example: `unix:/run/grpc-server`
8088
- *custom*: \
8189
You can define custom
8290
[`NameResolverProvider`s](https://javadoc.io/page/io.grpc/grpc-all/latest/io/grpc/NameResolverProvider.html) those
@@ -108,6 +116,50 @@ First of all most of the beans can be replaced by custom ones, that you can conf
108116
If you don't wish to go that far, you can use classes such as `GrpcChannelConfigurer` and `StubTransformer` to configure
109117
the channels, stubs and other components without losing the features provided by this library.
110118

119+
### GrpcClientBean
120+
121+
This annotation is used to create injectable beans from your otherwise non-injectable `@GrpcClient` instances.
122+
The annotation can be repeatedly added to any of your `@Configuration` classes.
123+
124+
> **Note:** We recommend using either `@GrpcClientBean`s or fields annotated with `@GrpcClient` throughout your
125+
> application, as mixing the two might cause confusion for future developers.
126+
127+
````java
128+
@Configuration
129+
@GrpcClientBean(
130+
clazz = TestServiceBlockingStub.class,
131+
beanName = "blockingStub",
132+
client = @GrpcClient("test")
133+
)
134+
@GrpcClientBean(
135+
clazz = FactoryMethodAccessibleStub.class,
136+
beanName = "accessibleStub",
137+
client = @GrpcClient("test"))
138+
public class YourCustomConfiguration {
139+
140+
@Bean
141+
FooService fooServiceBean(@Autowired TestServiceGrpc.TestServiceBlockingStub blockingStub) {
142+
return new FooService(blockingStub);
143+
}
144+
145+
}
146+
147+
@Service
148+
@AllArgsConsturtor
149+
public class BarService {
150+
151+
private FactoryMethodAccessibleStub accessibleStub;
152+
153+
public String receiveGreeting(String name) {
154+
HelloRequest request = HelloRequest.newBuilder()
155+
.setName(name)
156+
.build();
157+
return accessibleStub.sayHello(request).getMessage();
158+
}
159+
160+
}
161+
````
162+
111163
### GrpcChannelConfigurer
112164

113165
The grpc client configurer allows you to add your custom configuration to grpc's `ManagedChannelBuilder`s.
@@ -151,34 +203,48 @@ The following examples demonstrate how to use annotations to create a global cli
151203

152204
````java
153205
@Configuration
154-
public class ThirdPartyInterceptorConfig {}
206+
public class GlobalInterceptorConfiguration {
155207

156-
@GrpcGlobalServerInterceptor
157-
LogGrpcInterceptor logServerInterceptor() {
208+
@GrpcGlobalClientInterceptor
209+
LogGrpcInterceptor logClientInterceptor() {
158210
return new LogGrpcInterceptor();
159211
}
160212

161213
}
162214
````
163215

164-
This variant is very handy if you wish to add third-party interceptors to the global scope.
216+
The following example demonstrates creation via `GlobalClientInterceptorConfigurer`
217+
218+
````java
219+
@Configuration
220+
public class GlobalInterceptorConfiguration {
221+
222+
@Bean
223+
GlobalClientInterceptorConfigurer globalClientInterceptorConfigurer() {
224+
interceptors -> interceptors.add(new LogGrpcInterceptor());
225+
}
226+
227+
}
228+
````
229+
230+
These variant are very handy if you wish to add third-party interceptors to the global scope.
165231

166232
For your own interceptor implementations you can achieve the same result by adding the annotation to the class itself:
167233

168234
````java
169-
@GrpcGlobalServerInterceptor
170-
public class LogGrpcInterceptor implements ServerInterceptor {
235+
@GrpcGlobalClientInterceptor
236+
public class LogGrpcInterceptor implements ClientInterceptor {
171237

172238
private static final Logger log = LoggerFactory.getLogger(LogGrpcInterceptor.class);
173239

174240
@Override
175-
public <ReqT, RespT> ServerCall.Listener<ReqT> interceptCall(
176-
ServerCall<ReqT, RespT> serverCall,
177-
Metadata metadata,
178-
ServerCallHandler<ReqT, RespT> serverCallHandler) {
241+
public <ReqT, RespT> ClientCall<ReqT, RespT> interceptCall(
242+
final MethodDescriptor<ReqT, RespT> method,
243+
final CallOptions callOptions,
244+
final Channel next) {
179245

180-
log.info(serverCall.getMethodDescriptor().getFullMethodName());
181-
return serverCallHandler.startCall(serverCall, metadata);
246+
log.info(method.getFullMethodName());
247+
return next.newCall(method, callOptions);
182248
}
183249

184250
}
@@ -267,6 +333,7 @@ you have to define it via spring context (unless you wish to use `static`).
267333
- [Getting Started](getting-started.md)
268334
- *Configuration*
269335
- [Security](security.md)
336+
- [Tests with Grpc-Stubs](testing.md)
270337

271338
----------
272339

docs/en/client/getting-started.md

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,14 @@ If you don't wish to use any advanced features, then the first element is probab
106106
The annotation that marks fields and setters for auto injection of clients.
107107
Supports `Channel`s, and all kinds of `Stub`s.
108108
Do not use `@GrpcClient` in conjunction with `@Autowired` or `@Inject`.
109-
Currently it isn't supported for constructor and `@Bean` method parameters. \
109+
Currently, it isn't supported for constructor and `@Bean` method parameters. For this case look below
110+
to the `@GrpcClientBean`. \
110111
**Note:** Services provided by the same application can only be accessed/called in/after the
111112
`ApplicationStartedEvent`. Stubs connecting to services outside of the application can be used earlier; starting with
112113
`@PostConstruct` / `InitializingBean#afterPropertiesSet()`.
114+
- [`@GrpcClientBean`](https://javadoc.io/page/net.devh/grpc-client-spring-boot-autoconfigure/latest/net/devh/boot/grpc/client/inject/GrpcClientBean.html):
115+
The annotation helps to register `@GrpcClient` beans in the Spring context to be used with `@Autowired` and
116+
`@Qualifier`. The annotation can be repeatedly added to any of your `@Configuration` classes.
113117
- [`Channel`](https://javadoc.io/page/io.grpc/grpc-all/latest/io/grpc/Channel.html):
114118
The Channel is a connection pool for a single address. The target servers might serve multiple grpc-services though.
115119
The address will be resolved using a `NameResolver` and might point to a fixed or dynamic number of servers.
@@ -167,13 +171,51 @@ public class FoobarService {
167171
public String receiveGreeting(String name) {
168172
HelloRequest request = HelloRequest.newBuilder()
169173
.setName(name)
170-
.build()
174+
.build();
171175
return myServiceStub.sayHello(request).getMessage();
172176
}
173177

174178
}
175179
````
176180

181+
Also you can feel free to inject stub with `@GrpcClientBean` with `@Configuration` for more wide usage in
182+
another services.
183+
184+
> **Note:** We recommend using either `@GrpcClientBean`s or fields annotated with `@GrpcClient` throughout your
185+
> application, as mixing the two can cause confusion for future developers.
186+
187+
````java
188+
@Configuration
189+
@GrpcClientBean(
190+
clazz = TestServiceGrpc.TestServiceBlockingStub.class,
191+
beanName = "blockingStub",
192+
client = @GrpcClient("test")
193+
)
194+
public class YourCustomConfiguration {
195+
196+
@Bean
197+
FoobarService foobarService(@Autowired TestServiceGrpc.TestServiceBlockingStub blockingStub) {
198+
return new FoobarService(blockingStub);
199+
}
200+
201+
}
202+
203+
@Service
204+
@AllArgsConsturtor
205+
public class FoobarService {
206+
207+
private TestServiceBlockingStub blockingStub;
208+
209+
public String receiveGreeting(String name) {
210+
HelloRequest request = HelloRequest.newBuilder()
211+
.setName(name)
212+
.build();
213+
return blockingStub.sayHello(request).getMessage();
214+
}
215+
216+
}
217+
````
218+
177219
## Additional Topics <!-- omit in toc -->
178220

179221
- *Getting Started*

0 commit comments

Comments
 (0)