Add keep-alive property for GraphQL SSE handlers
This commit adds a new `spring.graphql.http.sse.keep-alive` configuration property for MVC and WebFlux SSE handlers. Closes gh-44743
This commit is contained in:
@@ -315,11 +315,24 @@ public class GraphQlProperties {
|
|||||||
|
|
||||||
public static class Sse {
|
public static class Sse {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* How frequently keep-alive messages should be sent.
|
||||||
|
*/
|
||||||
|
private Duration keepAlive;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Time required for concurrent handling to complete.
|
* Time required for concurrent handling to complete.
|
||||||
*/
|
*/
|
||||||
private Duration timeout;
|
private Duration timeout;
|
||||||
|
|
||||||
|
public Duration getKeepAlive() {
|
||||||
|
return this.keepAlive;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setKeepAlive(Duration keepAlive) {
|
||||||
|
this.keepAlive = keepAlive;
|
||||||
|
}
|
||||||
|
|
||||||
public Duration getTimeout() {
|
public Duration getTimeout() {
|
||||||
return this.timeout;
|
return this.timeout;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -94,7 +94,8 @@ public class GraphQlWebFluxAutoConfiguration {
|
|||||||
@Bean
|
@Bean
|
||||||
@ConditionalOnMissingBean
|
@ConditionalOnMissingBean
|
||||||
public GraphQlSseHandler graphQlSseHandler(WebGraphQlHandler webGraphQlHandler, GraphQlProperties properties) {
|
public GraphQlSseHandler graphQlSseHandler(WebGraphQlHandler webGraphQlHandler, GraphQlProperties properties) {
|
||||||
return new GraphQlSseHandler(webGraphQlHandler, properties.getHttp().getSse().getTimeout());
|
return new GraphQlSseHandler(webGraphQlHandler, properties.getHttp().getSse().getTimeout(),
|
||||||
|
properties.getHttp().getSse().getKeepAlive());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
|
|||||||
@@ -98,7 +98,8 @@ public class GraphQlWebMvcAutoConfiguration {
|
|||||||
@Bean
|
@Bean
|
||||||
@ConditionalOnMissingBean
|
@ConditionalOnMissingBean
|
||||||
public GraphQlSseHandler graphQlSseHandler(WebGraphQlHandler webGraphQlHandler, GraphQlProperties properties) {
|
public GraphQlSseHandler graphQlSseHandler(WebGraphQlHandler webGraphQlHandler, GraphQlProperties properties) {
|
||||||
return new GraphQlSseHandler(webGraphQlHandler, properties.getHttp().getSse().getTimeout());
|
return new GraphQlSseHandler(webGraphQlHandler, properties.getHttp().getSse().getTimeout(),
|
||||||
|
properties.getHttp().getSse().getKeepAlive());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
|
|||||||
@@ -42,6 +42,7 @@ import org.springframework.graphql.execution.RuntimeWiringConfigurer;
|
|||||||
import org.springframework.graphql.server.WebGraphQlHandler;
|
import org.springframework.graphql.server.WebGraphQlHandler;
|
||||||
import org.springframework.graphql.server.WebGraphQlInterceptor;
|
import org.springframework.graphql.server.WebGraphQlInterceptor;
|
||||||
import org.springframework.graphql.server.webflux.GraphQlHttpHandler;
|
import org.springframework.graphql.server.webflux.GraphQlHttpHandler;
|
||||||
|
import org.springframework.graphql.server.webflux.GraphQlSseHandler;
|
||||||
import org.springframework.graphql.server.webflux.GraphQlWebSocketHandler;
|
import org.springframework.graphql.server.webflux.GraphQlWebSocketHandler;
|
||||||
import org.springframework.http.HttpHeaders;
|
import org.springframework.http.HttpHeaders;
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
@@ -271,6 +272,24 @@ class GraphQlWebFluxAutoConfigurationTests {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void shouldConfigureSseTimeout() {
|
||||||
|
this.contextRunner.withPropertyValues("spring.graphql.http.sse.timeout=10s").run((context) -> {
|
||||||
|
assertThat(context).hasSingleBean(GraphQlSseHandler.class);
|
||||||
|
GraphQlSseHandler handler = context.getBean(GraphQlSseHandler.class);
|
||||||
|
assertThat(handler).hasFieldOrPropertyWithValue("timeout", Duration.ofSeconds(10));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void shouldConfigureSseKeepAlive() {
|
||||||
|
this.contextRunner.withPropertyValues("spring.graphql.http.sse.keep-alive=5s").run((context) -> {
|
||||||
|
assertThat(context).hasSingleBean(GraphQlSseHandler.class);
|
||||||
|
GraphQlSseHandler handler = context.getBean(GraphQlSseHandler.class);
|
||||||
|
assertThat(handler).hasFieldOrPropertyWithValue("keepAliveDuration", Duration.ofSeconds(5));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void routerFunctionShouldHaveOrderZero() {
|
void routerFunctionShouldHaveOrderZero() {
|
||||||
this.contextRunner.withUserConfiguration(CustomRouterFunctions.class).run((context) -> {
|
this.contextRunner.withUserConfiguration(CustomRouterFunctions.class).run((context) -> {
|
||||||
|
|||||||
@@ -108,6 +108,15 @@ class GraphQlWebMvcAutoConfigurationTests {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void shouldConfigureSseKeepAlive() {
|
||||||
|
this.contextRunner.withPropertyValues("spring.graphql.http.sse.keep-alive=5s").run((context) -> {
|
||||||
|
assertThat(context).hasSingleBean(GraphQlSseHandler.class);
|
||||||
|
GraphQlSseHandler handler = context.getBean(GraphQlSseHandler.class);
|
||||||
|
assertThat(handler).hasFieldOrPropertyWithValue("keepAliveDuration", Duration.ofSeconds(5));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void simpleQueryShouldWork() {
|
void simpleQueryShouldWork() {
|
||||||
withMockMvc((mvc) -> {
|
withMockMvc((mvc) -> {
|
||||||
|
|||||||
Reference in New Issue
Block a user