-
-
Notifications
You must be signed in to change notification settings - Fork 201
Expand file tree
/
Copy pathVertxApp.java
More file actions
58 lines (49 loc) · 1.43 KB
/
Copy pathVertxApp.java
File metadata and controls
58 lines (49 loc) · 1.43 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/*
* Jooby https://jooby.io
* Apache License Version 2.0 https://jooby.io/LICENSE.txt
* Copyright 2014 Edgar Espina
*/
package examples.vertx;
import static io.jooby.ExecutionMode.EVENT_LOOP;
import static io.jooby.vertx.VertxHandler.vertx;
import java.nio.file.Paths;
import java.util.Map;
import java.util.UUID;
import io.jooby.Jooby;
import io.jooby.netty.NettyServer;
import io.jooby.vertx.VertxModule;
import io.vertx.core.eventbus.EventBus;
import io.vertx.core.file.FileSystem;
import io.vertx.core.file.OpenOptions;
public class VertxApp extends Jooby {
{
install(new VertxModule());
var eb = require(EventBus.class);
eb.consumer(
"news.uk.sport",
message -> {
getLog().info("I have received a message: {}", message.body());
});
use(vertx());
get(
"/publish",
ctx -> {
ctx.require(EventBus.class)
.publish(
"news.uk.sport",
Map.of("msg", ctx.query("msg").value(UUID.randomUUID().toString())));
return "Sent";
});
get(
"/readme",
ctx -> {
var fs = ctx.require(FileSystem.class);
return fs.open(
Paths.get(System.getProperty("user.dir"), "pom.xml").toAbsolutePath().toString(),
new OpenOptions());
});
}
public static void main(String[] args) {
runApp(args, new NettyServer(), EVENT_LOOP, VertxApp::new);
}
}