props.put("bootstrap.servers", broker);
props.put("group.id", groupId); // ID für die Offset-Commits
props.put("client.id", clientId); // Nur zur Wiedererkennung
+ props.put("auto.offset.reset", "earliest"); // Von Beginn an lesen
props.put("partition.assignment.strategy", "org.apache.kafka.clients.consumer.CooperativeStickyAssignor");
props.put("key.deserializer", StringDeserializer.class.getName());
props.put("value.deserializer", StringDeserializer.class.getName());
{
try
{
- log.info("{} - Subscribing to topic test", id);
- consumer.subscribe(Arrays.asList("test"));
+ log.info("{} - Subscribing to topic {}", id, topic);
+ // TODO: subscribe!
running = true;
while (true)
{
- ConsumerRecords<String, String> records =
- consumer.poll(Duration.ofSeconds(1));
-
- log.info("{} - Received {} messages", id, records.count());
- for (ConsumerRecord<String, String> record : records)
- {
- consumed++;
- log.info(
- "{} - {}: {}/{} - {}={}",
- id,
- record.offset(),
- record.topic(),
- record.partition(),
- record.key(),
- record.value()
- );
- }
+ // TODO:
+ // * Poll for new records
+ // * Loop through received records
+ // * Count received records in the variable `consumed`
+ // * "Work" with the data: Log partition/offset/key/value
}
}
catch(WakeupException e)
}
catch(Exception e)
{
- log.error("{} - Unexpected error: {}", id, e.toString());
+ log.error("{} - Unexpected error: {}, unsubscribing!", id, e.toString());
}
finally
{