1 package de.juplo.kafka;
3 import lombok.RequiredArgsConstructor;
4 import lombok.extern.slf4j.Slf4j;
5 import org.apache.kafka.clients.consumer.ConsumerRecord;
6 import org.apache.kafka.clients.producer.Producer;
7 import org.apache.kafka.clients.producer.ProducerRecord;
10 @RequiredArgsConstructor
12 public class ApplicationRecordHandler implements RecordHandler<String, Integer>
14 private final Producer<String, Object> producer;
15 private final String id;
16 private final String topic;
20 public void accept(ConsumerRecord<String, Integer> record)
22 String key = record.key();
23 int number = record.value();
25 // TODO: JSON-Nachrichten verschicken
28 private void send(String key, Object value)
30 final long time = System.currentTimeMillis();
32 final ProducerRecord<String, Object> record = new ProducerRecord<>(
38 producer.send(record, (metadata, e) ->
40 long now = System.currentTimeMillis();
45 "{} - Sent key={} message={} partition={}/{} timestamp={} latency={}ms",
59 "{} - ERROR key={} timestamp={} latency={}ms: {}",
62 metadata == null ? -1 : metadata.timestamp(),
69 long now = System.currentTimeMillis();
71 "{} - Queued message with key={} latency={}ms",