Skip to content

Commit 33aa0e8

Browse files
author
Dave Syer
committed
Add sample with Shaded Netty
1 parent 6be591d commit 33aa0e8

File tree

8 files changed

+43
-24
lines changed

8 files changed

+43
-24
lines changed

README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,6 @@ As shown in the snippet below this can then be followed by version-less declarat
8585
```gradle
8686
dependencies {
8787
implementation platform("org.springframework.ai:spring-grpc-dependencies:1.0.0-SNAPSHOT")
88-
// Replace the following with the starter dependencies of specific modules you wish to use
89-
implementation 'org.springframework.ai:spring-grpc-openai'
9088
}
9189
```
9290

samples/grpc-server-netty-shaded

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Subproject commit 3b1a5d8494dd0c322086f02e8939ba89a2f31666

samples/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
<modules>
1919
<module>grpc-server</module>
20+
<module>grpc-server-netty-shaded</module>
2021
<module>grpc-tomcat</module>
2122
</modules>
2223

spring-grpc-docs/src/main/antora/modules/ROOT/pages/client.adoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ For Gradle users
5151
----
5252
dependencies {
5353
implementation "org.springframework.grpc:spring-grpc-spring-boot-starter"
54+
implementation 'io.grpc:grpc-netty-shaded'
5455
modules {
5556
module("io.grpc:grpc-netty") {
5657
replacedBy("io.grpc:grpc-netty-shaded", "Use Netty shaded instead of regular Netty")

spring-grpc-docs/src/main/antora/modules/ROOT/pages/server.adoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ For Gradle users
4747
----
4848
dependencies {
4949
implementation "org.springframework.grpc:spring-grpc-spring-boot-starter"
50+
implementation 'io.grpc:grpc-netty-shaded'
5051
modules {
5152
module("io.grpc:grpc-netty") {
5253
replacedBy("io.grpc:grpc-netty-shaded", "Use Netty shaded instead of regular Netty")

spring-grpc-docs/src/main/antora/modules/ROOT/partials/_configprops.adoc

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,23 @@
1212
|spring.grpc.client.default-channel.max-inbound-message-size | |
1313
|spring.grpc.client.default-channel.max-inbound-metadata-size | |
1414
|spring.grpc.client.default-channel.negotiation-type | | The negotiation type for the channel. Default is {@link NegotiationType#PLAINTEXT}.
15-
|spring.grpc.client.default-channel.secure | | Flag to say that strict SSL checks are not enabled (so the remote certificate could be anonymous).
15+
|spring.grpc.client.default-channel.secure | `+++true+++` | Flag to say that strict SSL checks are not enabled (so the remote certificate could be anonymous).
1616
|spring.grpc.client.default-channel.ssl.bundle | | SSL bundle name.
1717
|spring.grpc.client.default-channel.ssl.enabled | | Whether to enable SSL support. Enabled automatically if "bundle" is provided unless specified otherwise.
1818
|spring.grpc.client.default-channel.user-agent | |
1919
|spring.grpc.server.address | | The address to bind to. could be a host:port combination or a pseudo URL like static://host:port. Can not be set if host or port are set independently.
20-
|spring.grpc.server.host | | Server address to bind to. The default is any IP address ('*').
20+
|spring.grpc.server.host | `+++*+++` | Server address to bind to. The default is any IP address ('*').
2121
|spring.grpc.server.keep-alive.max-age | | Maximum time a connection may exist before being gracefully terminated (default infinite).
2222
|spring.grpc.server.keep-alive.max-age-grace | | Maximum time for graceful connection termination (default infinite).
2323
|spring.grpc.server.keep-alive.max-idle | | Maximum time a connection can remain idle before being gracefully terminated (default infinite).
24-
|spring.grpc.server.keep-alive.permit-time | | Maximum keep-alive time clients are permitted to configure (default 5m).
25-
|spring.grpc.server.keep-alive.permit-without-calls | | Whether clients are permitted to send keep alive pings when there are no outstanding RPCs on the connection (default false).
26-
|spring.grpc.server.keep-alive.time | | Duration without read activity before sending a keep alive ping (default 2h).
27-
|spring.grpc.server.keep-alive.timeout | | Maximum time to wait for read activity after sending a keep alive ping. If sender does not receive an acknowledgment within this time, it will close the connection (default 20s).
28-
|spring.grpc.server.max-inbound-message-size | | Maximum message size allowed to be received by the server (default 4MiB).
29-
|spring.grpc.server.max-inbound-metadata-size | | Maximum metadata size allowed to be received by the server (default 8KiB).
30-
|spring.grpc.server.port | | Server port to listen on. When the value is 0, a random available port is selected. The default is 9090.
31-
|spring.grpc.server.shutdown-grace-period | | Maximum time to wait for the server to gracefully shutdown. When the value is negative, the server waits forever. When the value is 0, the server will force shutdown immediately. The default is 30 seconds.
24+
|spring.grpc.server.keep-alive.permit-time | `+++5m+++` | Maximum keep-alive time clients are permitted to configure (default 5m).
25+
|spring.grpc.server.keep-alive.permit-without-calls | `+++false+++` | Whether clients are permitted to send keep alive pings when there are no outstanding RPCs on the connection (default false).
26+
|spring.grpc.server.keep-alive.time | `+++2h+++` | Duration without read activity before sending a keep alive ping (default 2h).
27+
|spring.grpc.server.keep-alive.timeout | `+++20s+++` | Maximum time to wait for read activity after sending a keep alive ping. If sender does not receive an acknowledgment within this time, it will close the connection (default 20s).
28+
|spring.grpc.server.max-inbound-message-size | `+++4194304B+++` | Maximum message size allowed to be received by the server (default 4MiB).
29+
|spring.grpc.server.max-inbound-metadata-size | `+++8192B+++` | Maximum metadata size allowed to be received by the server (default 8KiB).
30+
|spring.grpc.server.port | `+++9090+++` | Server port to listen on. When the value is 0, a random available port is selected. The default is 9090.
31+
|spring.grpc.server.shutdown-grace-period | `+++30s+++` | Maximum time to wait for the server to gracefully shutdown. When the value is negative, the server waits forever. When the value is 0, the server will force shutdown immediately. The default is 30 seconds.
3232
|spring.grpc.server.ssl.bundle | | SSL bundle name.
3333
|spring.grpc.server.ssl.enabled | | Whether to enable SSL support. Enabled automatically if "bundle" is provided unless specified otherwise.
3434

spring-grpc-spring-boot-autoconfigure/src/main/java/org/springframework/grpc/autoconfigure/server/GrpcServerAutoConfiguration.java

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -72,16 +72,4 @@ ServerBuilderCustomizers serverBuilderCustomizers(ObjectProvider<ServerBuilderCu
7272
return new ServerBuilderCustomizers(customizers.orderedStream().toList());
7373
}
7474

75-
@ConditionalOnBean(CompressorRegistry.class)
76-
@Bean
77-
ServerBuilderCustomizer<NettyServerBuilder> compressionServerConfigurer(CompressorRegistry registry) {
78-
return builder -> builder.compressorRegistry(registry);
79-
}
80-
81-
@ConditionalOnBean(DecompressorRegistry.class)
82-
@Bean
83-
ServerBuilderCustomizer<NettyServerBuilder> decompressionServerConfigurer(DecompressorRegistry registry) {
84-
return builder -> builder.decompressorRegistry(registry);
85-
}
86-
8775
}

spring-grpc-spring-boot-autoconfigure/src/main/java/org/springframework/grpc/autoconfigure/server/GrpcServerFactoryConfigurations.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import javax.net.ssl.KeyManagerFactory;
2222

2323
import org.springframework.beans.factory.ObjectProvider;
24+
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
2425
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
2526
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
2627
import org.springframework.boot.context.properties.EnableConfigurationProperties;
@@ -34,6 +35,8 @@
3435
import org.springframework.grpc.server.ShadedNettyGrpcServerFactory;
3536

3637
import io.grpc.BindableService;
38+
import io.grpc.CompressorRegistry;
39+
import io.grpc.DecompressorRegistry;
3740
import io.grpc.netty.NettyServerBuilder;
3841

3942
/**
@@ -67,6 +70,20 @@ ShadedNettyGrpcServerFactory shadedNettyGrpcServerFactory(GrpcServerProperties p
6770
return factory;
6871
}
6972

73+
@ConditionalOnBean(CompressorRegistry.class)
74+
@Bean
75+
ServerBuilderCustomizer<io.grpc.netty.shaded.io.grpc.netty.NettyServerBuilder> compressionServerConfigurer(
76+
CompressorRegistry registry) {
77+
return builder -> builder.compressorRegistry(registry);
78+
}
79+
80+
@ConditionalOnBean(DecompressorRegistry.class)
81+
@Bean
82+
ServerBuilderCustomizer<io.grpc.netty.shaded.io.grpc.netty.NettyServerBuilder> decompressionServerConfigurer(
83+
DecompressorRegistry registry) {
84+
return builder -> builder.decompressorRegistry(registry);
85+
}
86+
7087
}
7188

7289
@Configuration(proxyBeanMethods = false)
@@ -93,6 +110,18 @@ NettyGrpcServerFactory nettyGrpcServerFactory(GrpcServerProperties properties,
93110
return factory;
94111
}
95112

113+
@ConditionalOnBean(CompressorRegistry.class)
114+
@Bean
115+
ServerBuilderCustomizer<NettyServerBuilder> compressionServerConfigurer(CompressorRegistry registry) {
116+
return builder -> builder.compressorRegistry(registry);
117+
}
118+
119+
@ConditionalOnBean(DecompressorRegistry.class)
120+
@Bean
121+
ServerBuilderCustomizer<NettyServerBuilder> decompressionServerConfigurer(DecompressorRegistry registry) {
122+
return builder -> builder.decompressorRegistry(registry);
123+
}
124+
96125
}
97126

98127
}

0 commit comments

Comments
 (0)