projects
/
demos
/
kafka
/
training
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Merge branch 'stored-state' into stored-offsets
[demos/kafka/training]
/
src
/
main
/
java
/
de
/
juplo
/
kafka
/
EndlessConsumer.java
diff --git
a/src/main/java/de/juplo/kafka/EndlessConsumer.java
b/src/main/java/de/juplo/kafka/EndlessConsumer.java
index
b152310
..
2563204
100644
(file)
--- a/
src/main/java/de/juplo/kafka/EndlessConsumer.java
+++ b/
src/main/java/de/juplo/kafka/EndlessConsumer.java
@@
-34,7
+34,7
@@
public class EndlessConsumer implements Runnable
private KafkaConsumer<String, String> consumer = null;
private Future<?> future = null;
private KafkaConsumer<String, String> consumer = null;
private Future<?> future = null;
- private final Map<
TopicPartition, PartitionStatistics
> seen = new HashMap<>();
+ private final Map<
Integer, Map<String, Integer>
> seen = new HashMap<>();
public EndlessConsumer(
public EndlessConsumer(
@@
-81,17
+81,17
@@
public class EndlessConsumer implements Runnable
partitions.forEach(tp ->
{
log.info("{} - removing partition: {}", id, tp);
partitions.forEach(tp ->
{
log.info("{} - removing partition: {}", id, tp);
-
PartitionStatistics removed = seen.remove(tp
);
- for (
KeyCounter counter : removed.getStatistics
())
+
Map<String, Integer> removed = seen.remove(tp.partition()
);
+ for (
String key : removed.keySet
())
{
log.info(
"{} - Seen {} messages for partition={}|key={}",
id,
{
log.info(
"{} - Seen {} messages for partition={}|key={}",
id,
-
counter.getResult(
),
-
removed.getP
artition(),
-
counter.getKey()
);
+
removed.get(key
),
+
tp.p
artition(),
+
key
);
}
}
- repository.save(new StatisticsDocument(removed, consumer.position(tp)));
+ repository.save(new StatisticsDocument(
tp.partition(),
removed, consumer.position(tp)));
});
}
});
}
@@
-103,10
+103,10
@@
public class EndlessConsumer implements Runnable
log.info("{} - adding partition: {}", id, tp);
StatisticsDocument document =
repository
log.info("{} - adding partition: {}", id, tp);
StatisticsDocument document =
repository
- .findById(
tp.toString(
))
- .orElse(new StatisticsDocument(tp));
+ .findById(
Integer.toString(tp.partition()
))
+ .orElse(new StatisticsDocument(tp
.partition()
));
consumer.seek(tp, document.offset);
consumer.seek(tp, document.offset);
- seen.put(tp
, new PartitionStatistics(document)
);
+ seen.put(tp
.partition(), document.statistics
);
});
}
});
});
}
});
@@
-131,12
+131,23
@@
public class EndlessConsumer implements Runnable
record.value()
);
record.value()
);
-
TopicPartition partition = new TopicPartition(record.topic(), record.partition()
);
+
Integer partition = record.partition(
);
String key = record.key() == null ? "NULL" : record.key();
String key = record.key() == null ? "NULL" : record.key();
- seen.get(partition).increment(key);
+ Map<String, Integer> byKey = seen.get(partition);
+
+ if (!byKey.containsKey(key))
+ byKey.put(key, 0);
+
+ int seenByKey = byKey.get(key);
+ seenByKey++;
+ byKey.put(key, seenByKey);
}
}
- seen.forEach((tp, statistics) -> repository.save(new StatisticsDocument(statistics, consumer.position(tp))));
+ seen.forEach((partiton, statistics) -> repository.save(
+ new StatisticsDocument(
+ partiton,
+ statistics,
+ consumer.position(new TopicPartition(topic, partiton)))));
}
}
catch(WakeupException e)
}
}
catch(WakeupException e)
@@
-156,7
+167,7
@@
public class EndlessConsumer implements Runnable
}
}
}
}
- public Map<
TopicPartition, PartitionStatistics
> getSeen()
+ public Map<
Integer, Map<String, Integer>
> getSeen()
{
return seen;
}
{
return seen;
}