-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathCodeconProducer.java
49 lines (37 loc) · 1.54 KB
/
CodeconProducer.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
package codecon;
import org.apache.kafka.clients.producer.KafkaProducer;
import org.apache.kafka.clients.producer.Producer;
import org.apache.kafka.clients.producer.ProducerRecord;
import org.apache.kafka.clients.producer.RecordMetadata;
import java.util.List;
import java.util.Properties;
import java.util.concurrent.Future;
import java.util.stream.Collectors;
public class CodeconProducer {
private final Producer<String, String> producer;
private final String topic;
public CodeconProducer(Producer<String, String> producer, Properties props) {
this.producer = producer;
this.topic = props.getProperty("output.topic.name");
}
public static void main(final String[] args) throws Exception {
if (args.length < 2) {
throw new IllegalArgumentException(
"First argument is producer config file; second is the input data file.");
}
Properties props = Helpers.loadProperties(args[0]);
CodeconProducer application = new CodeconProducer(new KafkaProducer<>(props), props);
Runtime.getRuntime().addShutdownHook(new Thread(application::shutdown));
List<String> events = Helpers.readEventsFile(args[1]);
List<Future<RecordMetadata>> metadata = events.stream()
.map(application::produce)
.collect(Collectors.toList());
Helpers.printMetadata(metadata);
}
public Future<RecordMetadata> produce(String event) {
// TODO: Implementar
}
public void shutdown() {
producer.close();
}
}