-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
803 additions
and
109 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,8 @@ | ||
= Vert.x JPMS examples | ||
|
||
Here you will find examples demonstrating how Vert.x can be used with JPMS automatic modules. | ||
Here you will find examples demonstrating how Vert.x can be used with the Java Platform Module System (JPMS). | ||
|
||
The application is a Java 11 module that uses Vert.x jars with their automatic modules: | ||
This project contains several examples you can run in the IDE. | ||
|
||
- io.vertx.core; | ||
- requires io.vertx.web; | ||
- io.vertx.client.sql; | ||
- io.vertx.client.jdbc; | ||
- http2: a simple HTTP/2 link:src/main/java/io/vertx/examples/jpms/http2/Server.java[server] | ||
There are three examples, you can run these in the IDE | ||
|
||
- http2: a simple HTTP/2 server (io.vertx.example.jpms.http2.Server#main) | ||
- sqlclient: uses Vert.x SQL client (io.vertx.example.jpms.jdbc.Client#main) | ||
- web: a simplistic Vert.x Web app (io.vertx.example.jpms.web.Server#main) | ||
These examples focus on the declaration of Vert.x components used as JPMS automatic modules. | ||
|
||
To know more about | ||
|
||
- Vert.x Core: refers to the core-examples | ||
- Vert.x Web: refers to web-examples | ||
- Vert.x SQL Client: refers to jdbc-examples |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
jpms-examples/src/main/java/io/vertx/example/jpms/grpc/Server.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package io.vertx.example.jpms.grpc; | ||
|
||
import io.grpc.examples.helloworld.HelloReply; | ||
import io.grpc.examples.helloworld.HelloRequest; | ||
import io.grpc.examples.helloworld.VertxGreeterGrpcServer; | ||
import io.vertx.core.AbstractVerticle; | ||
import io.vertx.core.Future; | ||
import io.vertx.core.Promise; | ||
import io.vertx.core.Vertx; | ||
import io.vertx.core.http.HttpServer; | ||
import io.vertx.core.http.HttpServerOptions; | ||
import io.vertx.core.net.JksOptions; | ||
import io.vertx.grpc.server.GrpcServer; | ||
|
||
public class Server extends AbstractVerticle { | ||
|
||
public static void main(String[] args) { | ||
Vertx vertx = Vertx.vertx(); | ||
vertx.deployVerticle(new Server()) | ||
.onFailure(Throwable::printStackTrace); | ||
} | ||
|
||
@Override | ||
public void start(Promise<Void> startFuture) { | ||
HttpServer server = vertx.createHttpServer( | ||
new HttpServerOptions() | ||
.setUseAlpn(true) | ||
.setKeyCertOptions(new JksOptions().setPath("server-keystore.jks").setPassword("wibble")) | ||
.setSsl(false) | ||
); | ||
GrpcServer grpcServer = GrpcServer.server(vertx); | ||
VertxGreeterGrpcServer.GreeterApi api = new VertxGreeterGrpcServer.GreeterApi() { | ||
@Override | ||
public Future<HelloReply> sayHello(HelloRequest request) { | ||
return vertx.timer(200) | ||
.map(v -> HelloReply | ||
.newBuilder() | ||
.setMessage("Hello " + request.getName()) | ||
.build()); | ||
} | ||
}; | ||
api.bind_sayHello(grpcServer); | ||
server | ||
.requestHandler(grpcServer) | ||
.listen(8080) | ||
.<Void>mapEmpty() | ||
.onComplete(startFuture); | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
jpms-examples/src/main/java/io/vertx/example/jpms/http/Server.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package io.vertx.example.jpms.http; | ||
|
||
import io.vertx.core.AbstractVerticle; | ||
import io.vertx.core.Promise; | ||
import io.vertx.core.Vertx; | ||
import io.vertx.core.http.HttpServer; | ||
import io.vertx.core.json.JsonObject; | ||
|
||
public class Server extends AbstractVerticle { | ||
|
||
public static void main(String[] args) { | ||
Vertx vertx = Vertx.vertx(); | ||
vertx.deployVerticle(new Server()) | ||
.onFailure(Throwable::printStackTrace); | ||
} | ||
|
||
@Override | ||
public void start(Promise<Void> startFuture) { | ||
HttpServer server = vertx.createHttpServer(); | ||
server.requestHandler(req -> { | ||
req.response().end(new JsonObject() | ||
.put("http", req.version()) | ||
.put("message", "Hello World") | ||
.toString()); | ||
}).listen(8080) | ||
.<Void>mapEmpty() | ||
.onComplete(startFuture); | ||
} | ||
} |
Oops, something went wrong.