Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ protected boolean isNonNullAndNonBlank(final String value) {
}

/**
* Configures limits such as max message sizes that should be used by the channel.
* Configures limits such as max message or metadata sizes that should be used by the channel.
*
* @param builder The channel builder to configure.
* @param name The name of the client to configure.
Expand All @@ -245,6 +245,10 @@ protected void configureLimits(final T builder, final String name) {
if (maxInboundMessageSize != null) {
builder.maxInboundMessageSize((int) maxInboundMessageSize.toBytes());
}
final DataSize maxInboundMetadataSize = properties.getMaxInboundMetadataSize();
if (maxInboundMetadataSize != null) {
builder.maxInboundMetadataSize((int) maxInboundMetadataSize.toBytes());
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,41 @@ public void setMaxInboundMessageSize(final DataSize maxInboundMessageSize) {
}
}

@DataSizeUnit(DataUnit.BYTES)
private DataSize maxInboundMetadataSize = null;

/**
* Sets the maximum size of metadata in bytes allowed to be received.
* If not set ({@code null}) then it will default.The default is implementation-dependent, but is not generally less than 8 KiB and may be unlimited.
* If set to {@code -1} then it will use the highest possible limit (not recommended). Integer.MAX_VALUE disables the enforcement.
*
* @return The maximum size of metadata in bytes allowed to be received or null if the default should be used.
*
* @see ManagedChannelBuilder#maxInboundMetadataSize(int) (int)
*/
public DataSize getMaxInboundMetadataSize() {
return maxInboundMetadataSize;
}

/**
* Sets the maximum size of metadata in bytes allowed to be received.
* If not set ({@code null}) then it will default.The default is implementation-dependent, but is not generally less than 8 KiB and may be unlimited.
* If set to {@code -1} then it will use the highest possible limit (not recommended). Integer.MAX_VALUE disables the enforcement.
*
* @param maxInboundMetadataSize The new maximum size of metadata in bytes allowed to be received. {@code -1} for max
* possible. Null to use the gRPC's default.
*
* @see ManagedChannelBuilder#maxInboundMetadataSize(int) (int)
*/
public void setMaxInboundMetadataSize(DataSize maxInboundMetadataSize) {
if (maxInboundMetadataSize == null || maxInboundMetadataSize.toBytes() >= 0) {
this.maxInboundMetadataSize = maxInboundMetadataSize;
} else if (maxInboundMetadataSize.toBytes() == -1) {
this.maxInboundMetadataSize = DataSize.ofBytes(Integer.MAX_VALUE);
} else {
throw new IllegalArgumentException("Unsupported maxInboundMetadataSize: " + maxInboundMetadataSize);
}
}
// --------------------------------------------------

private Boolean fullStreamDecompression;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
@ExtendWith(SpringExtension.class)
@SpringBootTest(properties = {
"grpc.client.test.keepAliveTime=42m",
"grpc.client.test.maxInboundMessageSize=5MB"
"grpc.client.test.maxInboundMessageSize=5MB",
"grpc.client.test.maxInboundMetadataSize=3MB"
})
class GrpcChannelPropertiesGivenUnitTest {

Expand All @@ -45,6 +46,7 @@ void test() {
final GrpcChannelProperties properties = this.grpcChannelsProperties.getChannel("test");
assertEquals(Duration.ofMinutes(42), properties.getKeepAliveTime());
assertEquals(DataSize.ofMegabytes(5), properties.getMaxInboundMessageSize());
assertEquals(DataSize.ofMegabytes(3), properties.getMaxInboundMetadataSize());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
@ExtendWith(SpringExtension.class)
@SpringBootTest(properties = {
"grpc.client.test.keepAliveTime=42",
"grpc.client.test.maxInboundMessageSize=5242880"
"grpc.client.test.maxInboundMessageSize=5242880",
"grpc.client.test.maxInboundMetadataSize=3145728"
})
class GrpcChannelPropertiesNoUnitTest {

Expand All @@ -45,6 +46,7 @@ void test() {
final GrpcChannelProperties properties = this.grpcChannelsProperties.getChannel("test");
assertEquals(Duration.ofSeconds(42), properties.getKeepAliveTime());
assertEquals(DataSize.ofMegabytes(5), properties.getMaxInboundMessageSize());
assertEquals(DataSize.ofMegabytes(3), properties.getMaxInboundMetadataSize());
}

}