Heroku Kafka Connection Helper
![Maven Central](https://camo.githubusercontent.com/b27ccdaa78b66a7f57a8e3b3a3ae6d1f445cc00a173d2209dc35c307db8e5b02/68747470733a2f2f696d672e736869656c64732e696f2f6d6176656e2d63656e7472616c2f762f636f6d2e6164616d74686f64792f6865726f6b752d6b61666b612d636f6e6e656374696f6e2d68656c7065722e737667)
A Java library to help configure Kafka client connection Properties from Heroku Kafka environment variables.
Usage
Include this library in your application as a Maven dependency:
<dependency>
<groupId>com.adamthody</groupId>
<artifactId>heroku-kafka-connection-helper</artifactId>
<version>0.1.9</version>
</dependency>
Configuring a Client
Calling HerokuKafkaConnectionHelper.getConfigProperties()
will return a Properties object that has the appropriate connection properties set, as per the environment variables available.
Based on the URL scheme of the KAFKA_URL
environment variable, the properties will either be for a simple plaintext connection, or it will configure an SSL connection, including the KeyStore and TrustStore.
Heroku Kafka uses SSL by default, but by setting KAFKA_URL
locally, you can also test against a local cluster with a plaintext connection for local development without having to modify code.
Properties properties = HerokuKafkaConnectionHelper.getConfigProperties();
... // Additional properties
KafkaConsumer<Integer, String> consumer = new KafkaConsumer<>(properties);
If you're using Spring's ProducerFactory
or ConsumerFactory
, you may prefer to get your connection configuration as a Map.
Map<String, Object> configMap = HerokuKafkaConnectionHelper.getConfigMap();
... // Additional properties
ProducerFactory<Integer, String> producer = new DefaultKafkaProducerFactory<>(configMap);