Skip to content

Commit f257008

Browse files
committed
Doc updates: server side
1 parent 475386f commit f257008

File tree

2 files changed

+41
-5
lines changed

2 files changed

+41
-5
lines changed

README.adoc

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,44 @@ ifndef::env-github[]
9090
----
9191
include::pom.xml[tags="protobuf-maven-plugin",indent=0]
9292
----
93+
9394
<1> Properties prefixed `os.detected` are computed with the https://github.com/trustin/os-maven-plugin[os-maven-plugin] extension.
9495
<2> We choose to use the `CommonJS` modules generation style instead of closures.
9596
endif::env-github[]
97+
98+
=== The server side
99+
100+
The server side code fits in a single `ServerVerticle` class.
101+
102+
First, the gRPC server stub implementation.
103+
104+
ifdef::env-github[]
105+
link:src/main/java/io/vertx/howtos/grpcweb/ServerVerticle.java[Verticle file]
106+
endif::env-github[]
107+
ifndef::env-github[]
108+
[source,java]
109+
.gRPC server stub implementation
110+
----
111+
include::src/main/java/io/vertx/howtos/grpcweb/ServerVerticle.java[tags="grpcServer",indent=0]
112+
----
113+
endif::env-github[]
114+
115+
There is nothing specific to gRPC Web here.
116+
117+
NOTE: `GrpcIoServer` enables the gRPC Web protocol support by default.
118+
119+
Then we have to configure a Vert.x Web `Router` to accept both gRPC Web and static file requests.
120+
121+
ifdef::env-github[]
122+
link:src/main/java/io/vertx/howtos/grpcweb/ServerVerticle.java[Verticle file]
123+
endif::env-github[]
124+
ifndef::env-github[]
125+
[source,java]
126+
.Router and server configuration
127+
----
128+
include::src/main/java/io/vertx/howtos/grpcweb/ServerVerticle.java[tags="routerAndServer",indent=0]
129+
----
130+
131+
<1> All requests with `application/grpc-web-text` content type will be handed over to the `grpcServer`.
132+
<2> All other `GET` requests will be handled by a Vert.x Web `StaticHandler`.
133+
endif::env-github[]

src/main/java/io/vertx/howtos/grpcweb/ServerVerticle.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import io.vertx.core.Vertx;
77
import io.vertx.ext.web.Router;
88
import io.vertx.ext.web.handler.StaticHandler;
9-
import io.vertx.grpc.server.GrpcServerOptions;
109
import io.vertx.grpcio.server.GrpcIoServer;
1110
import io.vertx.grpcio.server.GrpcIoServiceBridge;
1211

@@ -23,19 +22,18 @@ public void sayHello(HelloRequest request, StreamObserver<HelloReply> responseOb
2322
}
2423
};
2524

26-
GrpcServerOptions grpcServerOptions = new GrpcServerOptions().setGrpcWebEnabled(true); // <2>
27-
GrpcIoServer grpcServer = GrpcIoServer.server(vertx, grpcServerOptions);
25+
GrpcIoServer grpcServer = GrpcIoServer.server(vertx);
2826
GrpcIoServiceBridge serverStub = GrpcIoServiceBridge.bridge(service);
2927
serverStub.bind(grpcServer);
3028
// end::grpcServer[]
3129

3230
// tag::routerAndServer[]
3331
Router router = Router.router(vertx);
3432
router.route()
35-
.consumes("application/grpc-web-text")
33+
.consumes("application/grpc-web-text") // <1>
3634
.handler(rc -> grpcServer.handle(rc.request()));
3735

38-
router.get().handler(StaticHandler.create());
36+
router.get().handler(StaticHandler.create()); // <2>
3937

4038
return vertx.createHttpServer()
4139
.requestHandler(router)

0 commit comments

Comments
 (0)