Skip to content

Commit

Permalink
Rewrite JPMS examples
Browse files Browse the repository at this point in the history
  • Loading branch information
vietj committed Sep 6, 2024
1 parent 3a23455 commit 8c18853
Show file tree
Hide file tree
Showing 15 changed files with 803 additions and 109 deletions.
22 changes: 3 additions & 19 deletions jpms-examples/README.adoc
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
236 changes: 213 additions & 23 deletions jpms-examples/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,60 +8,250 @@
<artifactId>jpms-examples</artifactId>
<version>5.0.0-SNAPSHOT</version>

<packaging>jlink</packaging>

<properties>
<protoc.version>4.27.2</protoc.version>
<testcontainers.version>1.20.1</testcontainers.version>
<native.transport></native.transport>
<osx.arch>aarch64</osx.arch>
</properties>

<repositories>
<repository>
<id>jpms-attic</id>
<name>JPMS Attic</name>
<url>https://jpms.pkg.st/repository</url>
</repository>
</repositories>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>io.vertx</groupId>
<artifactId>vertx-dependencies</artifactId>
<version>${project.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>

<dependency>
<groupId>io.vertx</groupId>
<artifactId>vertx-core</artifactId>
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>io.vertx</groupId>
<artifactId>vertx-web</artifactId>
<version>${project.version}</version>
<artifactId>vertx-grpc-server</artifactId>
<exclusions>
<exclusion>
<groupId>com.google.protobuf</groupId>
<artifactId>*</artifactId>
</exclusion>
<exclusion>
<groupId>com.google.guava</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.google.protobuf</groupId>
<artifactId>protobuf-java</artifactId>
<version>4.26.1-jpms</version>
</dependency>
<dependency>
<groupId>com.google.protobuf</groupId>
<artifactId>protobuf-util</artifactId>
<version>4.26.1-jpms</version>
<exclusions>
<exclusion>
<groupId>com.google.guava</groupId>
<artifactId>*</artifactId>
</exclusion>
<exclusion>
<groupId>com.google.code.findbugs</groupId>
<artifactId>*</artifactId>
</exclusion>
<exclusion>
<groupId>com.google.api.grpc</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>33.1.0-jre-jpms</version>
<exclusions>
<exclusion>
<groupId>com.google.guava</groupId>
<artifactId>listenablefuture</artifactId>
</exclusion>
<exclusion>
<groupId>com.google.code.findbugs</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>

<dependency>
<groupId>io.vertx</groupId>
<artifactId>vertx-jdbc-client</artifactId>
<version>${project.version}</version>
<artifactId>vertx-pg-client</artifactId>
</dependency>
<dependency>
<groupId>com.ongres.scram</groupId>
<artifactId>scram-client</artifactId>
<version>3.0</version>
</dependency>

<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-tcnative-classes</artifactId>
</dependency>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-tcnative-boringssl-static</artifactId>
<classifier>${os.detected.classifier}</classifier>
<version>2.0.66.Final</version>
</dependency>

<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-resolver-dns-classes-macos</artifactId>
</dependency>
<dependency>
<groupId>org.hsqldb</groupId>
<artifactId>hsqldb</artifactId>
<version>2.3.4</version>
<groupId>io.netty</groupId>
<artifactId>netty-resolver-dns-native-macos</artifactId>
<classifier>osx-${osx.arch}</classifier>
<version>4.2.0.Alpha4</version>
</dependency>

<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>2.0.13</version>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>testcontainers</artifactId>
<version>${testcontainers.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.9.1</version>
<scope>test</scope>
</dependency>
</dependencies>

<profiles>
<profile>
<id>mac</id>
<activation>
<os>
<family>mac</family>
</os>
</activation>
<properties>
<native.transport>kqueue</native.transport>
<osx.arch>${os.detected.arch}</osx.arch>
</properties>
<dependencies>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-transport-native-kqueue</artifactId>
<classifier>osx-${osx.arch}</classifier>
<version>4.2.0.Alpha4</version>
</dependency>
</dependencies>
</profile>
</profiles>

<build>

<extensions>
<extension>
<groupId>kr.motd.maven</groupId>
<artifactId>os-maven-plugin</artifactId>
<version>1.7.1</version>
</extension>
</extensions>
<pluginManagement>
<plugins>
<!-- We specify the Maven compiler plugin as we need to set it to Java 9 -->
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<version>3.13.0</version>
<configuration>
<source>11</source>
<target>11</target>
<release>11</release>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.5.0</version>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.xolstice.maven.plugins</groupId>
<artifactId>protobuf-maven-plugin</artifactId>
<version>0.6.1</version>
<configuration>
<!--
The version of protoc must match protobuf-java. If you don't depend on
protobuf-java directly, you will be transitively depending on the
protobuf-java version that grpc depends on.
-->
<protocArtifact>com.google.protobuf:protoc:${protoc.version}:exe:${os.detected.classifier}</protocArtifact>
<protocPlugins>
<protocPlugin>
<id>vertx-grpc-protoc-plugin</id>
<groupId>io.vertx</groupId>
<artifactId>vertx-grpc-protoc-plugin2</artifactId>
<version>${project.version}</version>
<mainClass>io.vertx.grpc.plugin.VertxGrpcServerGenerator</mainClass>
</protocPlugin>
</protocPlugins>
</configuration>
<executions>
<execution>
<id>compile</id>
<goals>
<goal>compile</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-jlink-plugin</artifactId>
<version>3.2.0</version>
<extensions>true</extensions>
<configuration>
<launcher>http=jpms.examples/io.vertx.example.jpms.http.Server</launcher>
<addModules>
<addModule>jdk.jdwp.agent</addModule>
<addModule>io.netty.resolver.dns.classes.macos</addModule>
<addModule>io.netty.resolver.dns.macos.osx.${osx.arch}</addModule>
<addModule>io.netty.transport.classes.${native.transport}</addModule>
<addModule>io.netty.transport.${native.transport}.${os.detected.name}.${os.detected.arch}</addModule>
<addModule>io.netty.internal.tcnative.openssl.${os.detected.name}.${os.detected.arch}</addModule>
</addModules>
</configuration>
</plugin>
</plugins>
</build>

<profiles>
<profile>
<id>staging</id>
<repositories>
<repository>
<id>staging</id>
<url>https://oss.sonatype.org/content/repositories/iovertx-3905/</url>
</repository>
</repositories>
</profile>
</profiles>

</project>
49 changes: 49 additions & 0 deletions jpms-examples/src/main/java/io/vertx/example/jpms/grpc/Server.java
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 jpms-examples/src/main/java/io/vertx/example/jpms/http/Server.java
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);
}
}
Loading

0 comments on commit 8c18853

Please sign in to comment.