Merge pull request #5 from deviceinsight/feature/correct-set-consumer-group

Refactor setting consumer group
This commit is contained in:
Paul Vorbach 2019-05-24 13:16:58 +02:00 committed by GitHub
commit 34ab41917b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 2 deletions

View File

@ -1,6 +1,10 @@
= KafkaHealthCheck = KafkaHealthCheck
:icons: font :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 == Version 0.1.0
* Develop kafka health check * Develop kafka health check

View File

@ -42,6 +42,7 @@ import javax.annotation.PreDestroy;
public class KafkaConsumingHealthIndicator extends AbstractHealthIndicator { public class KafkaConsumingHealthIndicator extends AbstractHealthIndicator {
private static final Logger logger = LoggerFactory.getLogger(KafkaConsumingHealthIndicator.class); private static final Logger logger = LoggerFactory.getLogger(KafkaConsumingHealthIndicator.class);
private static final String CONSUMER_GROUP_PREFIX = "health-check-";
private final Consumer<String, String> consumer; private final Consumer<String, String> consumer;
@ -95,8 +96,10 @@ public class KafkaConsumingHealthIndicator extends AbstractHealthIndicator {
private void setConsumerGroup(Map<String, Object> kafkaConsumerProperties) { private void setConsumerGroup(Map<String, Object> kafkaConsumerProperties) {
try { try {
kafkaConsumerProperties.putIfAbsent(ConsumerConfig.GROUP_ID_CONFIG, String groupId = (String) kafkaConsumerProperties.getOrDefault(ConsumerConfig.GROUP_ID_CONFIG,
"health-check-" + InetAddress.getLocalHost().getHostAddress()); UUID.randomUUID().toString());
kafkaConsumerProperties.put(ConsumerConfig.GROUP_ID_CONFIG,
CONSUMER_GROUP_PREFIX + groupId + "-" + InetAddress.getLocalHost().getHostAddress());
} catch (UnknownHostException e) { } catch (UnknownHostException e) {
throw new IllegalStateException(e); throw new IllegalStateException(e);
} }