Skip to content

Commit 8eb3fdc

Browse files
Add option in Spring Boot support to disable bidirectional streaming (#525)
1 parent 218feb8 commit 8eb3fdc

File tree

4 files changed

+56
-8
lines changed

4 files changed

+56
-8
lines changed

sdk-http-vertx/src/main/java/dev/restate/sdk/http/vertx/HttpEndpointRequestHandler.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import org.apache.logging.log4j.Logger;
3131
import org.jspecify.annotations.Nullable;
3232

33+
/** Vert.x HttpServer handler adapter for {@link Endpoint}. See {@link #fromEndpoint(Endpoint)}. */
3334
public class HttpEndpointRequestHandler implements Handler<HttpServerRequest> {
3435

3536
private static final Logger LOG = LogManager.getLogger(HttpEndpointRequestHandler.class);

sdk-http-vertx/src/main/java/dev/restate/sdk/http/vertx/RestateHttpServer.java

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,7 @@ public static int listen(HttpEndpointRequestHandler requestHandler) {
9090

9191
/** Like {@link #listen(Endpoint, int)}, with an already built request handler */
9292
public static int listen(HttpEndpointRequestHandler requestHandler, int port) {
93-
HttpServer server = Vertx.vertx().createHttpServer(DEFAULT_OPTIONS);
94-
server.requestHandler(requestHandler);
95-
return handleStart(server.listen(port));
93+
return handleStart(fromHandler(requestHandler).listen(port));
9694
}
9795

9896
/** Create a Vert.x {@link HttpServer} from the provided endpoint. */
@@ -134,9 +132,7 @@ public static HttpServer fromEndpoint(Vertx vertx, Endpoint.Builder endpointBuil
134132
* HttpServerOptions}.
135133
*/
136134
public static HttpServer fromEndpoint(Vertx vertx, Endpoint endpoint, HttpServerOptions options) {
137-
HttpServer server = vertx.createHttpServer(options);
138-
server.requestHandler(HttpEndpointRequestHandler.fromEndpoint(endpoint));
139-
return server;
135+
return fromHandler(vertx, HttpEndpointRequestHandler.fromEndpoint(endpoint), options);
140136
}
141137

142138
/** Like {@link #fromEndpoint(Vertx, Endpoint, HttpServerOptions)} */
@@ -145,6 +141,36 @@ public static HttpServer fromEndpoint(
145141
return fromEndpoint(vertx, endpointBuilder.build(), options);
146142
}
147143

144+
/** Create a Vert.x {@link HttpServer} from the provided {@link HttpEndpointRequestHandler}. */
145+
public static HttpServer fromHandler(HttpEndpointRequestHandler handler) {
146+
return fromHandler(handler, DEFAULT_OPTIONS);
147+
}
148+
149+
/**
150+
* Create a Vert.x {@link HttpServer} from the provided {@link HttpEndpointRequestHandler}, with
151+
* the given {@link HttpServerOptions}.
152+
*/
153+
public static HttpServer fromHandler(
154+
HttpEndpointRequestHandler handler, HttpServerOptions options) {
155+
return fromHandler(Vertx.vertx(), handler, options);
156+
}
157+
158+
/** Create a Vert.x {@link HttpServer} from the provided {@link HttpEndpointRequestHandler}. */
159+
public static HttpServer fromHandler(Vertx vertx, HttpEndpointRequestHandler handler) {
160+
return fromHandler(vertx, handler, DEFAULT_OPTIONS);
161+
}
162+
163+
/**
164+
* Create a Vert.x {@link HttpServer} from the provided {@link HttpEndpointRequestHandler}, with
165+
* the given {@link HttpServerOptions}.
166+
*/
167+
public static HttpServer fromHandler(
168+
Vertx vertx, HttpEndpointRequestHandler handler, HttpServerOptions options) {
169+
HttpServer server = vertx.createHttpServer(options);
170+
server.requestHandler(handler);
171+
return server;
172+
}
173+
148174
private static int handleStart(Future<HttpServer> fut) {
149175
try {
150176
HttpServer server = fut.toCompletionStage().toCompletableFuture().join();

sdk-spring-boot/src/main/java/dev/restate/sdk/springboot/RestateHttpEndpointBean.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
import dev.restate.sdk.auth.signing.RestateRequestIdentityVerifier;
1212
import dev.restate.sdk.endpoint.Endpoint;
13+
import dev.restate.sdk.http.vertx.HttpEndpointRequestHandler;
1314
import dev.restate.sdk.http.vertx.RestateHttpServer;
1415
import io.vertx.core.http.HttpServer;
1516
import java.util.Map;
@@ -74,7 +75,11 @@ public void afterPropertiesSet() {
7475
RestateRequestIdentityVerifier.fromKey(restateEndpointProperties.getIdentityKey()));
7576
}
7677

77-
this.server = RestateHttpServer.fromEndpoint(builder.build());
78+
this.server =
79+
RestateHttpServer.fromHandler(
80+
HttpEndpointRequestHandler.fromEndpoint(
81+
builder.build(),
82+
this.restateHttpServerProperties.isDisableBidirectionalStreaming()));
7883
}
7984

8085
@Override

sdk-spring-boot/src/main/java/dev/restate/sdk/springboot/RestateHttpServerProperties.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,30 @@
1717
public class RestateHttpServerProperties {
1818

1919
private final int port;
20+
private final boolean disableBidirectionalStreaming;
2021

2122
@ConstructorBinding
22-
public RestateHttpServerProperties(@Name("port") @DefaultValue(value = "9080") int port) {
23+
public RestateHttpServerProperties(
24+
@Name("port") @DefaultValue(value = "9080") int port,
25+
@Name("disableBidirectionalStreaming") @DefaultValue(value = "false")
26+
boolean disableBidirectionalStreaming) {
2327
this.port = port;
28+
this.disableBidirectionalStreaming = disableBidirectionalStreaming;
2429
}
2530

2631
/** Port to expose the HTTP server. */
2732
public int getPort() {
2833
return port;
2934
}
35+
36+
/**
37+
* If true, disable bidirectional streaming with HTTP/2 requests. Restate initiates for each
38+
* invocation a bidirectional streaming using HTTP/2 between restate-server and the SDK. In some
39+
* network setups, for example when using a load balancers that buffer request/response,
40+
* bidirectional streaming will not work correctly. Only in these scenarios, we suggest disabling
41+
* bidirectional streaming.
42+
*/
43+
public boolean isDisableBidirectionalStreaming() {
44+
return disableBidirectionalStreaming;
45+
}
3046
}

0 commit comments

Comments
 (0)