use of io.smallrye.reactive.messaging.kafka.api.IncomingKafkaRecordBatchMetadata in project smallrye-reactive-messaging by smallrye.
the class BatchConsumerTest method testIncomingConsumingMessageWithMetadata.
@Test
void testIncomingConsumingMessageWithMetadata() {
String newTopic = UUID.randomUUID().toString();
companion.topics().createAndWait(newTopic, 3);
KafkaMapBasedConfig config = kafkaConfig("mp.messaging.incoming.kafka").put("value.deserializer", StringDeserializer.class.getName()).put("auto.offset.reset", "earliest").put("topic", newTopic).put("batch", true);
BeanConsumingMessageWithBatchMetadata bean = runApplication(config, BeanConsumingMessageWithBatchMetadata.class);
companion.produceStrings().usingGenerator(i -> new ProducerRecord<>(newTopic, "k-" + i, "v-" + i), 10);
await().until(() -> bean.metadata().stream().mapToInt(m -> m.getRecords().count()).sum() == 10);
Map<TopicPartition, List<ConsumerRecord<String, String>>> records = new HashMap<>();
for (IncomingKafkaRecordBatchMetadata<String, String> metadata : bean.metadata()) {
for (TopicPartition partition : metadata.getRecords().partitions()) {
List<ConsumerRecord<String, String>> list = records.computeIfAbsent(partition, p -> new ArrayList<>());
list.addAll(metadata.getRecords().records(partition));
}
}
assertThat(records.keySet()).hasSize(3);
assertThat(records.values()).flatMap(l -> l).hasSize(10).allSatisfy(r -> {
assertThat(r.value()).startsWith("v-");
assertThat(r.key()).startsWith("k");
});
}
Aggregations