Skip to content

Commit 30ddee3

Browse files
committed
Upgrade to Vert.x 5
1 parent f9f0904 commit 30ddee3

File tree

7 files changed

+100
-50
lines changed

7 files changed

+100
-50
lines changed

README.adoc

+15-4
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ The _backend_ consumes messages sent to the `greetings` address, generates a gre
2727
== What you need
2828

2929
* A text editor or IDE
30-
* Java 8 higher
30+
* Java 11 higher
3131
* Maven or Gradle
3232
* https://kubernetes.io/docs/tasks/tools/install-minikube/[Minikube] or any Kubernetes cluster
3333
* `kubectl` command-line tool
@@ -46,7 +46,8 @@ Both projects depend on:
4646
* https://vertx.io/docs/vertx-health-check/java[`Vert.x Health Check`]
4747

4848
Vert.x Infinispan is a cluster manager for Vert.x based on the https://infinispan.org/[Infinispan] in-memory key/value data store.
49-
In Vert.x a cluster manager is used for various functions. In particular it provides discovery/membership of cluster nodes and stores _event bus_ subscription data.
49+
In Vert.x a cluster manager is used for various functions.
50+
In particular, it provides discovery/membership of cluster nodes and stores _event bus_ subscription data.
5051

5152
Vert.x Web is a set of building blocks which make it easy to create HTTP applications.
5253

@@ -286,7 +287,7 @@ The _backend_:
286287
----
287288

288289
TIP: Take note of the `backend` HTTP server port.
289-
By default it uses a random port to avoid conflict with the `frontend` HTTP server.
290+
By default, it uses a random port to avoid conflict with the `frontend` HTTP server.
290291

291292
NOTE: The following examples use the https://httpie.org/[HTTPie] command line HTTP client.
292293
Please refer to the https://httpie.org/doc#installation[installation] documentation if you don't have it installed on your system yet.
@@ -358,6 +359,7 @@ There are https://minikube.sigs.k8s.io/docs/handbook/pushing/[different ways] to
358359
In this document, we will push directly to the in-cluster Docker daemon.
359360
To do so, we must point our shell to Minikube's docker-daemon:
360361

362+
[source,shell]
361363
----
362364
eval $(minikube -p minikube docker-env)
363365
----
@@ -394,12 +396,14 @@ IMPORTANT: The headless service must account for pods even when not ready (`publ
394396

395397
Apply this configuration:
396398

399+
[source,shell]
397400
----
398401
kubectl apply -f headless-service.yml
399402
----
400403

401-
Then verify it was succesful:
404+
Then verify it was successful:
402405

406+
[source,shell]
403407
----
404408
kubectl get services clustered-app
405409
----
@@ -440,12 +444,14 @@ endif::env-github[]
440444

441445
Apply this configuration:
442446

447+
[source,shell]
443448
----
444449
kubectl apply -f frontend/deployment.yml
445450
----
446451

447452
Verify the pods have started successfully:
448453

454+
[source,shell]
449455
----
450456
kubectl get pods
451457
----
@@ -474,12 +480,14 @@ endif::env-github[]
474480

475481
Apply this configuration:
476482

483+
[source,shell]
477484
----
478485
kubectl apply -f frontend/service.yml
479486
----
480487

481488
Verify the service has been created successfully:
482489

490+
[source,shell]
483491
----
484492
kubectl get services frontend
485493
----
@@ -493,6 +501,7 @@ frontend LoadBalancer 10.106.16.88 <pending> 80:30729/TCP 62s
493501

494502
If you use Minikube, open another terminal window and run:
495503

504+
[source,shell]
496505
----
497506
minikube tunnel
498507
----
@@ -539,12 +548,14 @@ endif::env-github[]
539548

540549
Apply this configuration:
541550

551+
[source,shell]
542552
----
543553
kubectl apply -f backend/deployment.yml
544554
----
545555

546556
Verify the pods have started successfully:
547557

558+
[source,shell]
548559
----
549560
kubectl get pods
550561
----

backend/build.gradle.kts

+8-9
Original file line numberDiff line numberDiff line change
@@ -8,31 +8,30 @@ repositories {
88
mavenCentral()
99
}
1010

11-
val vertxVersion = "4.0.0"
11+
val vertxVersion = "5.0.0.CR2"
1212
val verticle = "io.vertx.howtos.cluster.BackendVerticle"
1313

1414
dependencies {
15+
implementation("io.vertx:vertx-launcher-application:${vertxVersion}")
1516
implementation("io.vertx:vertx-web:${vertxVersion}")
1617
implementation("io.vertx:vertx-infinispan:${vertxVersion}")
1718
implementation("io.vertx:vertx-health-check:${vertxVersion}")
18-
implementation("ch.qos.logback:logback-classic:1.2.3")
19+
implementation("ch.qos.logback:logback-classic:1.5.12")
1920
}
2021

2122
application {
22-
mainClassName = verticle
23+
applicationDefaultJvmArgs =
24+
listOf("-Djava.net.preferIPv4Stack=true", "-Dvertx.jgroups.config=default-configs/default-jgroups-udp.xml")
25+
mainClass = verticle
2326
}
2427

2528
jib {
2629
to {
2730
image = "clustering-kubernetes/backend"
2831
}
2932
container {
30-
mainClass = "io.vertx.core.Launcher"
31-
args = listOf("run", verticle, "-cluster")
33+
mainClass = "io.vertx.launcher.application.VertxApplication"
34+
args = listOf(verticle, "-cluster")
3235
ports = listOf("8080", "7800")
3336
}
3437
}
35-
36-
tasks.wrapper {
37-
gradleVersion = "5.2"
38-
}

backend/pom.xml

+26-7
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
<version>1.0-SNAPSHOT</version>
1010

1111
<properties>
12-
<maven.compiler.source>1.8</maven.compiler.source>
13-
<maven.compiler.target>1.8</maven.compiler.target>
1412
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
1513
<verticle>io.vertx.howtos.cluster.BackendVerticle</verticle>
1614
</properties>
@@ -20,14 +18,18 @@
2018
<dependency>
2119
<groupId>io.vertx</groupId>
2220
<artifactId>vertx-stack-depchain</artifactId>
23-
<version>4.0.0</version>
21+
<version>5.0.0.CR2</version>
2422
<type>pom</type>
2523
<scope>import</scope>
2624
</dependency>
2725
</dependencies>
2826
</dependencyManagement>
2927

3028
<dependencies>
29+
<dependency>
30+
<groupId>io.vertx</groupId>
31+
<artifactId>vertx-launcher-application</artifactId>
32+
</dependency>
3133
<dependency>
3234
<groupId>io.vertx</groupId>
3335
<artifactId>vertx-web</artifactId>
@@ -43,17 +45,35 @@
4345
<dependency>
4446
<groupId>ch.qos.logback</groupId>
4547
<artifactId>logback-classic</artifactId>
46-
<version>1.2.3</version>
48+
<version>1.5.12</version>
4749
</dependency>
4850
</dependencies>
4951

5052
<build>
5153
<plugins>
54+
<plugin>
55+
<groupId>org.apache.maven.plugins</groupId>
56+
<artifactId>maven-compiler-plugin</artifactId>
57+
<version>3.13.0</version>
58+
<configuration>
59+
<release>11</release>
60+
</configuration>
61+
</plugin>
5262
<plugin>
5363
<groupId>org.codehaus.mojo</groupId>
5464
<artifactId>exec-maven-plugin</artifactId>
55-
<version>1.5.0</version>
65+
<version>3.5.0</version>
5666
<configuration>
67+
<systemProperties>
68+
<systemProperty>
69+
<key>java.net.preferIPv4Stack</key>
70+
<value>true</value>
71+
</systemProperty>
72+
<systemProperty>
73+
<key>vertx.jgroups.config</key>
74+
<value>default-configs/default-jgroups-udp.xml</value>
75+
</systemProperty>
76+
</systemProperties>
5777
<mainClass>${verticle}</mainClass>
5878
</configuration>
5979
</plugin>
@@ -66,9 +86,8 @@
6686
<image>clustering-kubernetes/backend</image>
6787
</to>
6888
<container>
69-
<mainClass>io.vertx.core.Launcher</mainClass>
89+
<mainClass>io.vertx.launcher.application.VertxApplication</mainClass>
7090
<args>
71-
<arg>run</arg>
7291
<arg>${verticle}</arg>
7392
<arg>-cluster</arg>
7493
</args>

backend/src/main/java/io/vertx/howtos/cluster/BackendVerticle.java

+12-9
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
package io.vertx.howtos.cluster;
22

33
import io.vertx.core.*;
4+
import io.vertx.core.http.HttpServer;
45
import io.vertx.ext.cluster.infinispan.ClusterHealthCheck;
5-
import io.vertx.ext.healthchecks.HealthCheckHandler;
66
import io.vertx.ext.healthchecks.HealthChecks;
77
import io.vertx.ext.healthchecks.Status;
88
import io.vertx.ext.web.Router;
9+
import io.vertx.ext.web.healthchecks.HealthCheckHandler;
910
import org.slf4j.Logger;
1011
import org.slf4j.LoggerFactory;
1112

12-
public class BackendVerticle extends AbstractVerticle {
13+
public class BackendVerticle extends VerticleBase {
1314

1415
private static final Logger log = LoggerFactory.getLogger(BackendVerticle.class);
1516

@@ -20,23 +21,25 @@ public class BackendVerticle extends AbstractVerticle {
2021

2122
// tag::start[]
2223
@Override
23-
public void start() {
24-
registerConsumer();
24+
public Future<?> start() {
25+
Future<Void> registration = registerConsumer();
2526

2627
Router router = setupRouter();
2728

28-
vertx.createHttpServer()
29+
Future<HttpServer> httpServer = vertx.createHttpServer()
2930
.requestHandler(router)
3031
.listen(HTTP_PORT)
3132
.onSuccess(server -> log.info("Server started and listening on port {}", server.actualPort()));
33+
34+
return Future.join(registration, httpServer);
3235
}
3336
// end::start[]
3437

3538
// tag::consumer[]
36-
private void registerConsumer() {
37-
vertx.eventBus().<String>consumer("greetings", msg -> {
39+
private Future<Void> registerConsumer() {
40+
return vertx.eventBus().<String>consumer("greetings", msg -> {
3841
msg.reply(String.format("Hello %s from %s", msg.body(), POD_NAME));
39-
});
42+
}).completion();
4043
}
4144
// end::consumer[]
4245

@@ -57,7 +60,7 @@ private Router setupRouter() {
5760
public static void main(String[] args) {
5861
Vertx.clusteredVertx(new VertxOptions())
5962
.compose(vertx -> vertx.deployVerticle(new BackendVerticle()))
60-
.onFailure(Throwable::printStackTrace);
63+
.await();
6164
}
6265
// end::main[]
6366
}

frontend/build.gradle.kts

+8-9
Original file line numberDiff line numberDiff line change
@@ -8,31 +8,30 @@ repositories {
88
mavenCentral()
99
}
1010

11-
val vertxVersion = "4.0.0"
11+
val vertxVersion = "5.0.0.CR2"
1212
val verticle = "io.vertx.howtos.cluster.FrontendVerticle"
1313

1414
dependencies {
15+
implementation("io.vertx:vertx-launcher-application:${vertxVersion}")
1516
implementation("io.vertx:vertx-web:${vertxVersion}")
1617
implementation("io.vertx:vertx-infinispan:${vertxVersion}")
1718
implementation("io.vertx:vertx-health-check:${vertxVersion}")
18-
implementation("ch.qos.logback:logback-classic:1.2.3")
19+
implementation("ch.qos.logback:logback-classic:1.5.12")
1920
}
2021

2122
application {
22-
mainClassName = verticle
23+
applicationDefaultJvmArgs =
24+
listOf("-Djava.net.preferIPv4Stack=true", "-Dvertx.jgroups.config=default-configs/default-jgroups-udp.xml")
25+
mainClass = verticle
2326
}
2427

2528
jib {
2629
to {
2730
image = "clustering-kubernetes/frontend"
2831
}
2932
container {
30-
mainClass = "io.vertx.core.Launcher"
31-
args = listOf("run", verticle, "-cluster")
33+
mainClass = "io.vertx.launcher.application.VertxApplication"
34+
args = listOf(verticle, "-cluster")
3235
ports = listOf("8080", "7800")
3336
}
3437
}
35-
36-
tasks.wrapper {
37-
gradleVersion = "5.2"
38-
}

0 commit comments

Comments
 (0)