Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kafka Backend group ID configuration make easier #391

Merged
merged 3 commits into from
Nov 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/main/java/com/purbon/kafka/topology/Configuration.java
Original file line number Diff line number Diff line change
Expand Up @@ -565,4 +565,8 @@ private void generateRandomJulieInstanceId() {
.toString();
}
}

public String getKafkaBackendConsumerGroupId() {
return config.getString(JULIE_KAFKA_CONSUMER_GROUP_ID);
}
}
1 change: 1 addition & 0 deletions src/main/java/com/purbon/kafka/topology/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -136,5 +136,6 @@ public class Constants {
public static final String JULIE_ROLES = "julie.roles";

public static final String JULIE_KAFKA_CONFIG_TOPIC = "julie.kafka.config.topic";
public static final String JULIE_KAFKA_CONSUMER_GROUP_ID = "julie.kafka.consumer.group.id";
public static final String JULIE_INSTANCE_ID = "julie.instance.id";
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,8 @@ public void configure() {
var serde = new JsonDeserializer<>(BackendState.class);
consumerProperties.put(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, serde.getClass());
consumerProperties.put(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "earliest");
consumerProperties.put(
GROUP_ID_CONFIG,
consumerProperties.get(GROUP_ID_CONFIG).toString() + System.currentTimeMillis());

consumerProperties.put(GROUP_ID_CONFIG, config.getKafkaBackendConsumerGroupId());
consumer = new KafkaConsumer<>(consumerProperties);
consumer.subscribe(Collections.singletonList(config.getJulieKafkaConfigTopic()));
}
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/reference.conf
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ julie {
kafka.config.topic = "__julieops_commands"
kafka.config.topic = ${?JULIE_KAFKA_CONFIG_TOPIC}
instance.id = ${?JULIE_INSTANCE_ID}
kafka.consumer.group.id = "julieops"
kafka.consumer.group.id = ${?JULIE_KAFKA_CONSUMER_GROUP_ID}
}

confluent {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import static com.purbon.kafka.topology.CommandLineInterface.BROKERS_OPTION;
import static com.purbon.kafka.topology.Constants.JULIE_INSTANCE_ID;
import static com.purbon.kafka.topology.Constants.JULIE_KAFKA_CONSUMER_GROUP_ID;
import static org.assertj.core.api.Assertions.assertThat;

import com.purbon.kafka.topology.Configuration;
Expand Down Expand Up @@ -39,7 +40,6 @@ public void before() throws IOException {

props = new Properties();
props.put(JULIE_INSTANCE_ID, "1234");
props.put(ConsumerConfig.GROUP_ID_CONFIG, "group.id");

Map<String, Object> saslConfig =
ContainerTestUtils.getSaslConfig(
Expand Down Expand Up @@ -80,6 +80,11 @@ public void testExpectedFlow() throws IOException, InterruptedException {
backend.close();

KafkaBackend newBackend = new KafkaBackend();

HashMap<String, String> cliOps = new HashMap<>();
cliOps.put(BROKERS_OPTION, container.getBootstrapServers());
props.put(JULIE_KAFKA_CONSUMER_GROUP_ID, "julieops"+System.currentTimeMillis());
Configuration config = new Configuration(cliOps, props);
newBackend.configure(config);

Thread.sleep(3000);
Expand Down