Skip to content

Commit e0754b2

Browse files
authored
feat: Enable more Kafka logging and reduce timeout (#20)
feat: Enable Kafka network logging at warning level to catch warnings relating to the brokers being unavailable. feat: 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 <katheris@uk.ibm.com>
1 parent cad6305 commit e0754b2

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,6 @@ Test out the app by connecting to the websocket endpoints (UI will be added soon
3838
To configure the application to connect to your Kafka edit the properties file called `kafka.properties`.
3939
Alternatively you can provide a custom path to the properties file using `-Dproperties_path=<path>` when starting the application.
4040

41-
If your Kafka is secured you will need to enable the security configuration options in your properties file
41+
If your Kafka is secured you will need to enable the security configuration options in your properties file.
42+
43+
To increase the logging level to debug provide a system property at start time: `-Dlog.level=debug`.

src/main/java/kafka/vertx/demo/PeriodicProducer.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import io.vertx.core.json.JsonObject;
1313
import io.vertx.kafka.client.producer.KafkaProducer;
1414
import io.vertx.kafka.client.producer.KafkaProducerRecord;
15+
import org.apache.kafka.clients.producer.ProducerConfig;
1516
import org.slf4j.Logger;
1617
import org.slf4j.LoggerFactory;
1718

@@ -35,9 +36,12 @@ public void start(Promise<Void> startPromise) {
3536
}
3637

3738
private void setup(HashMap<String, String> props) {
39+
// Don't retry and only wait 10 secs for partition info as this is a demo app
40+
props.put(ProducerConfig.RETRIES_CONFIG, "0");
41+
props.put(ProducerConfig.MAX_BLOCK_MS_CONFIG, "10000");
3842
KafkaProducer<String, String> kafkaProducer = KafkaProducer.create(vertx, props);
3943

40-
kafkaProducer.exceptionHandler(err -> logger.error("Kafka error: {}", err));
44+
kafkaProducer.exceptionHandler(err -> logger.debug("Kafka error: {}", err));
4145

4246
TimeoutStream timerStream = vertx.periodicStream(2000);
4347
timerStream.handler(tick -> produceKafkaRecord(kafkaProducer, props.get(Main.TOPIC_KEY)));

src/main/resources/logback.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@
99
<logger name="io.netty" level="warn"/>
1010
<logger name="io.vertx" level="info"/>
1111
<logger name="org.apache.kafka" level="error"/>
12+
<logger name="org.apache.kafka.clients.NetworkClient" level="warn"/>
1213

13-
<root level="info">
14+
<root level="${log.level:-info}">
1415
<appender-ref ref="STDOUT"/>
1516
</root>
1617

0 commit comments

Comments
 (0)