I'm creating a new Kafka consumer like this in Java (some code omitted for brevity)
final Properties props = new Properties();
props.put(ConsumerConfig.GROUP_ID_CONFIG, "group2");
final Consumer<Long, String> consumer = new KafkaConsumer<>(props);
consumer.subscribe(Collections.singletonList("topicname"));
This creates also the consumer group automatically, in case it does not yet exist. The problem is that the offset of this consumer group is not at the beginning of the topic, but at the end.
How can I ensure that the offset is at 0 when group is created (but not otherwise)? I don't want to manually track the offset, just set it to 0 when creating the consumer if the consumer group does not yet exist.