From ea78787c67df2f061e53ea0f8e8fe87f05d4b423 Mon Sep 17 00:00:00 2001 From: Katherine Stanley Date: Fri, 19 Jun 2020 17:25:31 +0100 Subject: [PATCH] feat: Enable more Kafka logging and reduce timeout Enable Kafka network logging at warning level to catch warnings relating to the brokers being unavailable. Reduce the timeout for getting partitions data to see errors more quickly and do no retry as the app will try again due to to TimeoutStream. Signed-off-by: Katherine Stanley --- README.md | 4 +++- src/main/java/kafka/vertx/demo/PeriodicProducer.java | 6 +++++- src/main/resources/logback.xml | 3 ++- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 3b0a5d4c..8ff8036e 100644 --- a/README.md +++ b/README.md @@ -38,4 +38,6 @@ Test out the app by connecting to the websocket endpoints (UI will be added soon To configure the application to connect to your Kafka edit the properties file called `kafka.properties`. Alternatively you can provide a custom path to the properties file using `-Dproperties_path=` when starting the application. -If your Kafka is secured you will need to enable the security configuration options in your properties file +If your Kafka is secured you will need to enable the security configuration options in your properties file. + +To increase the logging level to debug provide a system property at start time: `-Dlog.level=debug`. diff --git a/src/main/java/kafka/vertx/demo/PeriodicProducer.java b/src/main/java/kafka/vertx/demo/PeriodicProducer.java index a57c50c1..431fd741 100644 --- a/src/main/java/kafka/vertx/demo/PeriodicProducer.java +++ b/src/main/java/kafka/vertx/demo/PeriodicProducer.java @@ -12,6 +12,7 @@ import io.vertx.core.json.JsonObject; import io.vertx.kafka.client.producer.KafkaProducer; import io.vertx.kafka.client.producer.KafkaProducerRecord; +import org.apache.kafka.clients.producer.ProducerConfig; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -35,9 +36,12 @@ public void start(Promise startPromise) { } private void setup(HashMap props) { + // Don't retry and only wait 10 secs for partition info as this is a demo app + props.put(ProducerConfig.RETRIES_CONFIG, "0"); + props.put(ProducerConfig.MAX_BLOCK_MS_CONFIG, "10000"); KafkaProducer kafkaProducer = KafkaProducer.create(vertx, props); - kafkaProducer.exceptionHandler(err -> logger.error("Kafka error: {}", err)); + kafkaProducer.exceptionHandler(err -> logger.debug("Kafka error: {}", err)); TimeoutStream timerStream = vertx.periodicStream(2000); timerStream.handler(tick -> produceKafkaRecord(kafkaProducer, props.get(Main.TOPIC_KEY))); diff --git a/src/main/resources/logback.xml b/src/main/resources/logback.xml index 3065cccd..10f29c9e 100644 --- a/src/main/resources/logback.xml +++ b/src/main/resources/logback.xml @@ -9,8 +9,9 @@ + - +