You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: documentation/spring-boot-docs/src/docs/antora/modules/reference/pages/io/grpc.adoc
+23-23Lines changed: 23 additions & 23 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,16 +2,16 @@
2
2
= gRPC
3
3
4
4
Google Remote Procedure Call (gRPC) is a high-performance RPC framework that enables client-server communication using binary messages.
5
-
Spring Boot include support for developing and testing both client and server gRPC applications.
5
+
Spring Boot includes support for developing and testing both client and server gRPC applications.
6
6
7
-
The underling message format used by gRPC is Protocol Buffers which allow messages to be created and consumed by a wide variety of programming languages.
7
+
The underlying message format used by gRPC is Protocol Buffers, which allow messages to be created and consumed by a wide variety of programming languages.
8
8
9
9
10
10
11
11
[[io.grpc.servicedefinitions]]
12
12
== Service Definitions
13
13
14
-
To develop a gRPC application you first need a Protocol Buffers service definition file.
14
+
To develop a gRPC application, you first need a Protocol Buffers service definition file.
15
15
A `.proto` file defines the services and messages that your application can consume or provide.
16
16
17
17
Here's an example of a typical `.proto` file that uses https://protobuf.dev/programming-guides/proto3/[the `proto3` revision] of the protocol buffers language:
@@ -36,29 +36,29 @@ message HelloReply {
36
36
}
37
37
----
38
38
39
-
This file defines a `HelloWorld` service with a single method that accepts a `HelloReqest` message and return a `HelloReply` message.
40
-
The `HelloReqest` message contains a `name` string field.
39
+
This file defines a `HelloWorld` service with a single method that accepts a `HelloRequest` message and returns a `HelloReply` message.
40
+
The `HelloRequest` message contains a `name` string field.
41
41
The `HelloReply` message contains a `message` string field.
42
42
43
-
With the exception of a the `java_package` and `java_multiple_files` options, there is nothing in the `.proto` file that is specific to the Java programming langage.
43
+
With the exception of the `java_package` and `java_multiple_files` options, there is nothing in the `.proto` file that is specific to the Java programming language.
44
44
45
45
46
46
47
47
[[io.grpc.servicedefinitions.generatingjavacode]]
48
48
=== Generating Java Code
49
49
50
50
Since `.proto` files are language agnostic, we need a process to convert them into usable Java code.
51
-
We can then use the generated code to either make a remote procedure call to running service, or implement the service ourselves so that others may call it.
51
+
We can then use the generated code to either make a remote procedure call to a running service or implement the service ourselves so that others may call it.
52
52
53
53
The exact process you use to generate code will depend on your build system.
54
-
Spring Boot supports for both Maven and Gradle protobuf plugins, but you are free to use whatever solution works best for you.
54
+
Spring Boot supports both Maven and Gradle protobuf plugins, but you are free to use whatever solution works best for you.
Spring Boot include dependency management for the `com.google.protobuf:protobuf-gradle-plugin` Gradle plugin.
134
+
Spring Boot includes dependency management for the `com.google.protobuf:protobuf-gradle-plugin` Gradle plugin.
135
135
In addition, the `spring-boot-gradle-plugin` will react to the presence of the protobuf plugin and configure it appropriately.
136
136
137
137
The following shows a typical Gradle file that uses the plugin:
@@ -163,7 +163,7 @@ endif::[]
163
163
}
164
164
----
165
165
166
-
Since this gradle file uses both the `org.springframework.boot` and `com.google.protobuf` plugins, you'll get the following:
166
+
Since this Gradle file uses both the `org.springframework.boot` and `com.google.protobuf` plugins, you'll get the following:
167
167
168
168
* Configuration of the `protoc` version.
169
169
* Configuration of the `protoc-gen-grpc-java` version.
@@ -179,11 +179,11 @@ TIP: If you don't use `org.springframework.boot` plugin, or you want to configur
179
179
180
180
Spring Boot provides a `spring-boot-grpc-server` module and a `spring-boot-starter-grpc-server` starter POM that you can use for server applications.
181
181
182
-
In order to write the actual server code, you'll need to extended one or more of base classes generated from your `.proto` file and expose them as Spring beans.
182
+
In order to write the actual server code, you'll need to extend one or more of the base classes generated from your `.proto` file and expose them as Spring beans.
183
183
Spring gRPC will automatically expose any bean that implements javadoc:io.grpc.BindableService[] as a gRPC server.
184
184
Since all `.proto` generated classes implement javadoc:io.grpc.BindableService[], adding them as beans is enough to expose them over gRPC.
185
185
186
-
TIP: For more details see {url-spring-grpc-docs}/server.html#_create_a_grpc_service[the Spring gRPC documentation].
186
+
TIP: For more details, see {url-spring-grpc-docs}/server.html#_create_a_grpc_service[the Spring gRPC documentation].
187
187
188
188
The following example shows how the `HelloWorld` service from the `.proto` file above could be implemented.
189
189
In this example, we're using the javadoc:org.springframework.grpc.server.service.GrpcService[format=annotation] annotation and assuming that the code is in a package that will be picked up by component scanning:
If you find that the version of Netty provided by the `spring-boot-starter-grpc-server` starter POM isn't compatible with other libraries you use, you can switch to a "`shaded`" version.
215
215
216
-
To switch, you can excluded `io.grpc:grpc-netty` and include `io.grpc:grpc-netty-shaded`.
216
+
To switch, you can exclude `io.grpc:grpc-netty` and include `io.grpc:grpc-netty-shaded`.
217
217
For example:
218
218
219
219
@@ -317,10 +317,10 @@ dependencies {
317
317
+
318
318
======
319
319
320
-
TIP: Remember to include a Servlet Container dependency, for example using `spring-boot-starter-tomcat`, and to set `server.http2.enabled` to `true`.
320
+
TIP: Remember to include a Servlet Container dependency – `spring-boot-starter-tomcat`, for example – and to set configprop:server.http2.enabled[] to `true`.
321
321
322
322
NOTE: When using a servlet container, certain gRPC server configuration properties are not relevant and will be ignored.
323
-
For example, configprop:spring.grpc.server.port[] is ignored since configprop:server.port[] used used to set a web server port.
323
+
For example, configprop:spring.grpc.server.port[] is ignored since configprop:server.port[] is used to set a web server port.
324
324
325
325
326
326
@@ -343,7 +343,7 @@ spring:
343
343
344
344
Client authentication can also be configured by setting configprop:spring.grpc.server.ssl.client-auth[] to `optional` or `require`.
345
345
346
-
TIP: To temporarily disable server SSL support, for example to aid with testing, you can set configprop:spring.grpc.server.ssl.enabled[] to `false`.
346
+
TIP: To temporarily disable server SSL support – to aid with testing, for example – set configprop:spring.grpc.server.ssl.enabled[] to `false`.
347
347
348
348
349
349
@@ -604,7 +604,7 @@ You can configure gRPC connections to use standard one-way-TLS, or mutual TLS
604
604
==== Standard one-way TLS
605
605
606
606
To use standard one-way TLS, you can set the `ssl.enabled` property to `true` in your channel properties.
607
-
For example, the following will enabled an SSL/TLS connection for the `myservice` channel:
607
+
For example, the following will enable an SSL/TLS connection for the `myservice` channel:
608
608
609
609
[configprops,yaml]
610
610
----
@@ -643,7 +643,7 @@ spring:
643
643
644
644
[TIP]
645
645
====
646
-
To temporarily disable client SSL support, for example to aid with testing, you can set `bypass-certificate-validation` to `true` on your channel config:
646
+
To temporarily disable client SSL support – to aid with testing, for example – set `bypass-certificate-validation` to `true` on your channel config:
647
647
648
648
[configprops,yaml]
649
649
----
@@ -667,7 +667,7 @@ In this mode, the in-process channel factory is auto-configured in addition to t
667
667
To prevent users from having to deal with multiple channel factories, a composite channel factory is configured as the primary channel factory bean.
668
668
The composite consults its composed factories to find the first one that supports the channel target.
669
669
670
-
To use the in-process server the channel target must be set to `in-process:<name>`
670
+
To use the in-process server, the channel target must be set to `in-process:<name>`
671
671
672
672
TIP: To disable the in-process channel factory, you can set the configprop:spring.grpc.client.inprocess.enabled[] property to `false`.
To help test your gRPC client and server applications you can use the `spring-boot-grpc-test` module or the `spring-boot-starter-grpc-client-test` / `spring-boot-starter-grpc-server-test` starter POMs.
703
+
To help test your gRPC client and server applications, you can use the `spring-boot-grpc-test` module or the `spring-boot-starter-grpc-client-test` / `spring-boot-starter-grpc-server-test` starter POMs.
704
704
705
705
706
706
[[io.grpc.testing.test-transport]]
707
707
=== Using In-Process Test Transport
708
708
709
709
The javadoc:org.springframework.boot.grpc.test.autoconfigure.AutoConfigureTestGrpcTransport[format=annotation] annotation allows you to quickly replace gRPC communication channels with in-process channels specifically designed for testing.
710
-
Unlike regular in-process channels, these test channels to not require any configuration.
710
+
Unlike regular in-process channels, these test channels do not require any configuration.
711
711
712
712
Using test gRPC transport means that you don't need to actually listen on a network port to start your application.
713
713
This allows your tests to run quickly, whilst still ensuring that your application works as expected.
0 commit comments