diff --git a/changelog.adoc b/changelog.adoc index b36a541..ef78a69 100644 --- a/changelog.adoc +++ b/changelog.adoc @@ -1,6 +1,10 @@ = KafkaHealthCheck :icons: font +== Version 1.1.0 + +* Make consumer groups unique by appending a random UUID when no group ID is configured explicitly. + == Version 0.1.0 * Develop kafka health check diff --git a/src/main/java/com/deviceinsight/kafka/health/KafkaConsumingHealthIndicator.java b/src/main/java/com/deviceinsight/kafka/health/KafkaConsumingHealthIndicator.java index 63d0865..14ae92b 100644 --- a/src/main/java/com/deviceinsight/kafka/health/KafkaConsumingHealthIndicator.java +++ b/src/main/java/com/deviceinsight/kafka/health/KafkaConsumingHealthIndicator.java @@ -42,6 +42,7 @@ import javax.annotation.PreDestroy; public class KafkaConsumingHealthIndicator extends AbstractHealthIndicator { private static final Logger logger = LoggerFactory.getLogger(KafkaConsumingHealthIndicator.class); + private static final String CONSUMER_GROUP_PREFIX = "health-check-"; private final Consumer consumer; @@ -95,8 +96,10 @@ public class KafkaConsumingHealthIndicator extends AbstractHealthIndicator { private void setConsumerGroup(Map kafkaConsumerProperties) { try { - kafkaConsumerProperties.putIfAbsent(ConsumerConfig.GROUP_ID_CONFIG, - "health-check-" + InetAddress.getLocalHost().getHostAddress()); + String groupId = (String) kafkaConsumerProperties.getOrDefault(ConsumerConfig.GROUP_ID_CONFIG, + UUID.randomUUID().toString()); + kafkaConsumerProperties.put(ConsumerConfig.GROUP_ID_CONFIG, + CONSUMER_GROUP_PREFIX + groupId + "-" + InetAddress.getLocalHost().getHostAddress()); } catch (UnknownHostException e) { throw new IllegalStateException(e); }