Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -30,6 +30,7 @@
import org.apache.logging.log4j.Logger;
import org.jspecify.annotations.Nullable;

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

private static final Logger LOG = LogManager.getLogger(HttpEndpointRequestHandler.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,7 @@ public static int listen(HttpEndpointRequestHandler requestHandler) {

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

/** Create a Vert.x {@link HttpServer} from the provided endpoint. */
Expand Down Expand Up @@ -134,9 +132,7 @@ public static HttpServer fromEndpoint(Vertx vertx, Endpoint.Builder endpointBuil
* HttpServerOptions}.
*/
public static HttpServer fromEndpoint(Vertx vertx, Endpoint endpoint, HttpServerOptions options) {
HttpServer server = vertx.createHttpServer(options);
server.requestHandler(HttpEndpointRequestHandler.fromEndpoint(endpoint));
return server;
return fromHandler(vertx, HttpEndpointRequestHandler.fromEndpoint(endpoint), options);
}

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

/** Create a Vert.x {@link HttpServer} from the provided {@link HttpEndpointRequestHandler}. */
public static HttpServer fromHandler(HttpEndpointRequestHandler handler) {
return fromHandler(handler, DEFAULT_OPTIONS);
}

/**
* Create a Vert.x {@link HttpServer} from the provided {@link HttpEndpointRequestHandler}, with
* the given {@link HttpServerOptions}.
*/
public static HttpServer fromHandler(
HttpEndpointRequestHandler handler, HttpServerOptions options) {
return fromHandler(Vertx.vertx(), handler, options);
}

/** Create a Vert.x {@link HttpServer} from the provided {@link HttpEndpointRequestHandler}. */
public static HttpServer fromHandler(Vertx vertx, HttpEndpointRequestHandler handler) {
return fromHandler(vertx, handler, DEFAULT_OPTIONS);
}

/**
* Create a Vert.x {@link HttpServer} from the provided {@link HttpEndpointRequestHandler}, with
* the given {@link HttpServerOptions}.
*/
public static HttpServer fromHandler(
Vertx vertx, HttpEndpointRequestHandler handler, HttpServerOptions options) {
HttpServer server = vertx.createHttpServer(options);
server.requestHandler(handler);
return server;
}

private static int handleStart(Future<HttpServer> fut) {
try {
HttpServer server = fut.toCompletionStage().toCompletableFuture().join();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

import dev.restate.sdk.auth.signing.RestateRequestIdentityVerifier;
import dev.restate.sdk.endpoint.Endpoint;
import dev.restate.sdk.http.vertx.HttpEndpointRequestHandler;
import dev.restate.sdk.http.vertx.RestateHttpServer;
import io.vertx.core.http.HttpServer;
import java.util.Map;
Expand Down Expand Up @@ -74,7 +75,11 @@ public void afterPropertiesSet() {
RestateRequestIdentityVerifier.fromKey(restateEndpointProperties.getIdentityKey()));
}

this.server = RestateHttpServer.fromEndpoint(builder.build());
this.server =
RestateHttpServer.fromHandler(
HttpEndpointRequestHandler.fromEndpoint(
builder.build(),
this.restateHttpServerProperties.isDisableBidirectionalStreaming()));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,30 @@
public class RestateHttpServerProperties {

private final int port;
private final boolean disableBidirectionalStreaming;

@ConstructorBinding
public RestateHttpServerProperties(@Name("port") @DefaultValue(value = "9080") int port) {
public RestateHttpServerProperties(
@Name("port") @DefaultValue(value = "9080") int port,
@Name("disableBidirectionalStreaming") @DefaultValue(value = "false")
boolean disableBidirectionalStreaming) {
this.port = port;
this.disableBidirectionalStreaming = disableBidirectionalStreaming;
}

/** Port to expose the HTTP server. */
public int getPort() {
return port;
}

/**
* If true, disable bidirectional streaming with HTTP/2 requests. Restate initiates for each
* invocation a bidirectional streaming using HTTP/2 between restate-server and the SDK. In some
* network setups, for example when using a load balancers that buffer request/response,
* bidirectional streaming will not work correctly. Only in these scenarios, we suggest disabling
* bidirectional streaming.
*/
public boolean isDisableBidirectionalStreaming() {
return disableBidirectionalStreaming;
}
}