forked from vert-x3/vertx-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMainVerticle.java
63 lines (53 loc) · 1.77 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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package io.vertx.example.kafka.dashboard;
import io.debezium.kafka.KafkaCluster;
import io.debezium.util.Testing;
import io.vertx.core.AbstractVerticle;
import io.vertx.core.DeploymentOptions;
import io.vertx.core.Vertx;
import io.vertx.core.json.JsonObject;
import org.apache.kafka.clients.consumer.OffsetResetStrategy;
import java.io.File;
import java.util.Map;
import java.util.Properties;
/**
* @author <a href="mailto:julien@julienviet.com">Julien Viet</a>
*/
public class MainVerticle extends AbstractVerticle {
public static void main(String[] args) {
Vertx vertx = Vertx.vertx();
vertx.deployVerticle(new MainVerticle());
}
private KafkaCluster kafkaCluster;
@Override
public void start() throws Exception {
// Kafka setup for the example
File dataDir = Testing.Files.createTestingDirectory("cluster");
dataDir.deleteOnExit();
kafkaCluster = new KafkaCluster()
.usingDirectory(dataDir)
.withPorts(2181, 9092)
.addBrokers(1)
.deleteDataPriorToStartup(true)
.startup();
// Deploy the dashboard
JsonObject consumerConfig = new JsonObject((Map) kafkaCluster.useTo()
.getConsumerProperties("the_group", "the_client", OffsetResetStrategy.LATEST));
vertx.deployVerticle(
DashboardVerticle.class.getName(),
new DeploymentOptions().setConfig(consumerConfig)
);
// Deploy the metrics collector : 3 times
for (int i = 0;i < 3;i++) {
JsonObject producerConfig = new JsonObject((Map) kafkaCluster.useTo()
.getProducerProperties("the_producer-" + i));
vertx.deployVerticle(
MetricsVerticle.class.getName(),
new DeploymentOptions().setConfig(producerConfig)
);
}
}
@Override
public void stop() throws Exception {
kafkaCluster.shutdown();
}
}