Make Tomcat sample work with grpcurl

This commit is contained in:
Dave Syer
2025-01-22 07:55:20 +00:00
parent 495d14b48d
commit c7b1ed3684
2 changed files with 31 additions and 0 deletions

View File

@@ -1,7 +1,15 @@
package org.springframework.grpc.sample;
import java.util.Arrays;
import org.apache.coyote.UpgradeProtocol;
import org.apache.coyote.http2.Http2Protocol;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.embedded.tomcat.TomcatConnectorCustomizer;
import org.springframework.context.annotation.Bean;
import io.netty.handler.ssl.ApplicationProtocolConfig.Protocol;
@SpringBootApplication
public class GrpcServerApplication {
@@ -10,4 +18,15 @@ public class GrpcServerApplication {
SpringApplication.run(GrpcServerApplication.class, args);
}
@Bean
public TomcatConnectorCustomizer customizer() {
return (connector) -> {
for (UpgradeProtocol protocol : connector.findUpgradeProtocols()) {
if (protocol instanceof Http2Protocol http2Protocol) {
http2Protocol.setOverheadWindowUpdateThreshold(0);
}
}
};
}
}

View File

@@ -2,6 +2,8 @@ package org.springframework.grpc.sample;
import static org.junit.jupiter.api.Assertions.assertEquals;
import java.util.Iterator;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.junit.jupiter.api.Test;
@@ -43,6 +45,16 @@ public class GrpcServerApplicationTests {
assertEquals("Hello ==> Alien", response.getMessage());
}
@Test
@DirtiesContext
void streamResponds() {
Iterator<HelloReply> response = stub.streamHello(HelloRequest.newBuilder().setName("Alien").build());
assertEquals("Hello(0) ==> Alien", response.next().getMessage());
while (response.hasNext()) {
log.info(response.next().getMessage());
}
}
@TestConfiguration
static class ExtraConfiguration {