1. Kafka
Kafka module for https://kafka.apache.org/documentation
1.1. Usage
1) Add the dependency:
Maven
Gradle
<dependency>
<groupId>io.jooby</groupId>
<artifactId>jooby-kafka</artifactId>
<version>3.5.3</version>
</dependency>
2) Setup properties:
application.conf
kafka.producer.bootstrap.servers = "localhost:9092"
kafka.producer.key.serializer = "org.apache.kafka.common.serialization.StringSerializer"
kafka.producer.value.serializer = "org.apache.kafka.common.serialization.StringSerializer"
kafka.consumer.bootstrap.servers = "localhost:9092"
kafka.consumer.key.deserializer = "org.apache.kafka.common.serialization.StringDeserializer"
kafka.consumer.value.deserializer = "org.apache.kafka.common.serialization.StringDeserializer"
3) Install
Java
Kotlin
import io.jooby.kafka.KafkaModule;
{
install(new KafkaModule()); (1)
get("/", ctx -> {
KafkaProducer producer = require(KafkaProducer.class); (2)
// work with producer
KafkaConsumer consumer = require(KafkaConsumer.class); (3)
// work with consumer
...
});
}
1 | Install module |
2 | Use KafkaProducer |
3 | Use KafkaConsumer |
Optionally, you can install just a consumer:
install(new KafkaConsumerModule());
Or producer:
install(new KafkaProducerModule());