Skip to content

Commit

Permalink
Refine config properties for default channel
Browse files Browse the repository at this point in the history
Because of spring-projects/spring-boot#43352
there's no point having a "default" entry in the channels map.
  • Loading branch information
dsyer committed Dec 4, 2024
1 parent 5c0ca70 commit acbe334
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ then in `application.properties`:
spring.grpc.client.channels.local.address=0.0.0.0:9090
----

There is a default named channel (named "default") that you can configure in the same way, and then it will be used by default if there is no channel with the name specified in the channel creation.
There is a default named channel that you can configure as `spring.grpc.client.default-channel.*`, and then it will be used by default if there is no channel with the name specified in the channel creation.

Beans of type `GrpcChannelBuilderCustomizer` can be used to customize the `ChannelBuilder` before the channel is built.
This can be useful for setting up security, for example.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,47 +2,14 @@
|Name | Default | Description

|spring.grpc.client.channels | |
|spring.grpc.client.default-channel.address | |
|spring.grpc.client.default-channel.default-load-balancing-policy | |
|spring.grpc.client.default-channel.enable-keep-alive | |
|spring.grpc.client.default-channel.health.enabled | | Whether to enable client-side health check for the channel.
|spring.grpc.client.default-channel.health.service-name | | Name of the service to check health on.
|spring.grpc.client.default-channel.idle-timeout | |
|spring.grpc.client.default-channel.keep-alive-time | |
|spring.grpc.client.default-channel.keep-alive-timeout | |
|spring.grpc.client.default-channel.keep-alive-without-calls | |
|spring.grpc.client.default-channel.max-inbound-message-size | |
|spring.grpc.client.default-channel.max-inbound-metadata-size | |
|spring.grpc.client.default-channel.negotiation-type | | The negotiation type for the channel. Default is {@link NegotiationType#PLAINTEXT}.
|spring.grpc.client.default-channel.secure | `+++true+++` | Flag to say that strict SSL checks are not enabled (so the remote certificate could be anonymous).
|spring.grpc.client.default-channel.ssl.bundle | | SSL bundle name.
|spring.grpc.client.default-channel.ssl.enabled | | Whether to enable SSL support. Enabled automatically if "bundle" is provided unless specified otherwise.
|spring.grpc.client.default-channel.user-agent | |
|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.
|spring.grpc.server.exception-handling.enabled | `+++true+++` | Whether to enable user-defined global exception handling on the gRPC server.
|spring.grpc.server.health.actuator.enabled | `+++true+++` | Whether to adapt Actuator health indicators into gRPC health checks.
|spring.grpc.server.health.actuator.health-indicator-paths | | List of Actuator health indicator paths to adapt into gRPC health checks.
|spring.grpc.server.health.actuator.update-initial-delay | `+++5s+++` | The initial delay before updating the health status the very first time.
|spring.grpc.server.health.actuator.update-overall-health | `+++true+++` | Whether to update the overall gRPC server health (the '' service) with the aggregate status of the configured health indicators.
|spring.grpc.server.health.actuator.update-rate | `+++5s+++` | How often to update the health status.
|spring.grpc.server.health.enabled | `+++true+++` | Whether to auto-configure Health feature on the gRPC server.
|spring.grpc.server.host | `+++*+++` | Server address to bind to. The default is any IP address ('*').
|spring.grpc.server.keep-alive.max-age | | Maximum time a connection may exist before being gracefully terminated (default infinite).
|spring.grpc.server.keep-alive.max-age-grace | | Maximum time for graceful connection termination (default infinite).
|spring.grpc.server.keep-alive.max-idle | | Maximum time a connection can remain idle before being gracefully terminated (default infinite).
|spring.grpc.server.keep-alive.permit-time | `+++5m+++` | Maximum keep-alive time clients are permitted to configure (default 5m).
|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).
|spring.grpc.server.keep-alive.time | `+++2h+++` | Duration without read activity before sending a keep alive ping (default 2h).
|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).
|spring.grpc.server.max-inbound-message-size | `+++4194304B+++` | Maximum message size allowed to be received by the server (default 4MiB).
|spring.grpc.server.max-inbound-metadata-size | `+++8192B+++` | Maximum metadata size allowed to be received by the server (default 8KiB).
|spring.grpc.server.host | | Server address to bind to. The default is any IP address ('*').
|spring.grpc.server.max-inbound-message-size | | Maximum message size allowed to be received by the server (default 4MiB).
|spring.grpc.server.max-inbound-metadata-size | | Maximum metadata size allowed to be received by the server (default 8KiB).
|spring.grpc.server.observations.enabled | `+++true+++` | Whether to enable Observations on the server.
|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.
|spring.grpc.server.reflection.enabled | `+++true+++` | Whether to enable Reflection on the gRPC server.
|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.
|spring.grpc.server.ssl.bundle | | SSL bundle name.
|spring.grpc.server.ssl.client-auth | | Client authentication mode.
|spring.grpc.server.ssl.enabled | | Whether to enable SSL support. Enabled automatically if "bundle" is provided unless specified otherwise.
|spring.grpc.server.ssl.secure | `+++true+++` | Flag to indicate that client authentication is secure (i.e. certificates are checked). Do not set this to false in production.
|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.

|===
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public class GrpcClientProperties implements EnvironmentAware {

private NamedChannel defaultChannel = new NamedChannel();

private Map<String, NamedChannel> channels = new HashMap<>(Map.of("default", defaultChannel));
private Map<String, NamedChannel> channels = new HashMap<>();

private Environment environment = new StandardEnvironment();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ void withDefaultNameReturnsDefaultChannel() {
GrpcClientProperties properties = new GrpcClientProperties();
var defaultChannel = properties.getDefaultChannel();
assertThat(properties.getChannel("default")).isSameAs(defaultChannel);
assertThat(properties.getChannels()).containsExactly(entry("default", defaultChannel));
assertThat(properties.getChannels()).hasSize(0);
}

@Test
Expand All @@ -210,8 +210,7 @@ void withUnknownNameReturnsNewChannelWithCopiedDefaults() {
defaultChannel.getSsl().setBundle("custom-bundle");
var newChannel = properties.getChannel("new");
assertThat(newChannel).usingRecursiveComparison().ignoringFields("address").isEqualTo(defaultChannel);
assertThat(properties.getChannels()).containsExactly(entry("default", defaultChannel),
entry("new", newChannel));
assertThat(properties.getChannels()).containsExactly(entry("new", newChannel));
}

}
Expand All @@ -225,7 +224,7 @@ void withCustomChannelReturnsCustomChannelAddress() {
map.put("spring.grpc.client.channels.custom.address", "static://my-server:8888");
GrpcClientProperties properties = bindProperties(map);
assertThat(properties.getTarget("custom")).isEqualTo("my-server:8888");
assertThat(properties.getChannels()).containsOnlyKeys("default", "custom");
assertThat(properties.getChannels()).containsOnlyKeys("custom");
}

}
Expand Down

0 comments on commit acbe334

Please sign in to comment.