-
Notifications
You must be signed in to change notification settings - Fork 2.1k
/
MainVerticle.java
36 lines (31 loc) · 1.11 KB
/
MainVerticle.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package io.vertx.example.core.verticle.worker;
import io.vertx.core.AbstractVerticle;
import io.vertx.core.DeploymentOptions;
import io.vertx.core.Launcher;
import io.vertx.core.ThreadingModel;
/**
* An example illustrating how worker verticles can be deployed and how to interact with them.
*
* This example prints the name of the current thread at various locations to exhibit the event loop <-> worker
* thread switches.
*/
public class MainVerticle extends AbstractVerticle {
public static void main(String[] args) {
Launcher.executeCommand("run", MainVerticle.class.getName());
}
@Override
public void start() throws Exception {
System.out.println("[Main] Running in " + Thread.currentThread().getName());
vertx
.deployVerticle("io.vertx.example.core.verticle.worker.WorkerVerticle",
new DeploymentOptions().setThreadingModel(ThreadingModel.WORKER));
vertx.eventBus().request(
"sample.data",
"hello vert.x",
r -> {
System.out.println("[Main] Receiving reply ' " + r.result().body()
+ "' in " + Thread.currentThread().getName());
}
);
}
}