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 'rebalance-listener' into stored-state
[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
e67bf41
..
7cb77aa
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(
@@
-80,17
+80,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));
+ repository.save(new StatisticsDocument(
tp.partition(),
removed));
});
}
});
}
@@
-101,11
+101,11
@@
public class EndlessConsumer implements Runnable
{
log.info("{} - adding partition: {}", id, tp);
seen.put(
{
log.info("{} - adding partition: {}", id, tp);
seen.put(
- tp,
+ tp
.partition()
,
repository
repository
- .findById(
tp.toString(
))
- .map(
PartitionStatistics::new
)
- .orElse(new
PartitionStatistics(tp
)));
+ .findById(
Integer.toString(tp.partition()
))
+ .map(
document -> document.statistics
)
+ .orElse(new
HashMap<>(
)));
});
}
});
});
}
});
@@
-130,9
+130,16
@@
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);
}
}
}
}
}
}
@@
-153,7
+160,7
@@
public class EndlessConsumer implements Runnable
}
}
}
}
- public Map<
TopicPartition, PartitionStatistics
> getSeen()
+ public Map<
Integer, Map<String, Integer>
> getSeen()
{
return seen;
}
{
return seen;
}