https://github.com/bootique/bootique-kafka
Provides integration of Kafka client and streams with Bootique
https://github.com/bootique/bootique-kafka
bootique kafka kafka-client
Last synced: about 1 year ago
JSON representation
Provides integration of Kafka client and streams with Bootique
- Host: GitHub
- URL: https://github.com/bootique/bootique-kafka
- Owner: bootique
- License: apache-2.0
- Created: 2016-06-28T20:35:12.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2025-04-19T13:22:58.000Z (about 1 year ago)
- Last Synced: 2025-04-19T18:03:33.664Z (about 1 year ago)
- Topics: bootique, kafka, kafka-client
- Language: Java
- Homepage: http://bootique.io
- Size: 348 KB
- Stars: 4
- Watchers: 6
- Forks: 4
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://github.com/bootique/bootique-kafka/actions/workflows/maven.yml)
[](https://search.maven.org/artifact/io.bootique.kafka/bootique-kafka-client/)
# bootique-kafka
## Dependencies
Include the BOMs and then ```bootique-kafka-client```:
```xml
io.bootique.bom
bootique-bom
3.0-M4
pom
import
...
io.bootique.kafka
bootique-kafka-client
io.bootique.kafka
bootique-kafka-streams
```
## Producer/Consumer Configuration
Configure parameters in the YAML. Note that practically all of these settings can be overridden when creating a
specific Producer or Consumer instance via `KafkaProducerFactory` or `KafkaConsumerFactory`. So this is just a
collection of defaults for the most typical Producer or Consumer:
```yaml
kafkaclient:
# any number of named clusters, specifying comma-separated bootstrap Kafka servers for each.
clusters:
cluster1: 127.0.0.1:9092
cluster2: host1:9092,host2:9092
consumer:
autoCommit: true
autoCommitInterval: "200ms"
defaultGroup: myappgroup
sessionTimeout: "2s"
producer:
acks: all # values are "all" or numeric number for min acks
retries: 1
batchSize: 16384
linger: "1ms"
bufferMemory: 33554432
```
Now you can inject producer and consumer factories and create any number of producers and consumers (for more details
see [bootique-kafka-examples](https://github.com/bootique-examples/bootique-kafka-examples)).
Producer:
```java
@Inject
KafkaProducerFactory factory;
public void runProducer() {
Producer producer = factory
.charValueProducer()
.cluster("cluster2")
.create();
producer.send(new ProducerRecord<>("mytopic", "Hi!"));
// close if there's nothing else to send
producer.close();
}
```
Consumer example (also see [this code sample](https://github.com/bootique-examples/bootique-kafka-consumer)) :
```java
@Inject
KafkaConsumerFactory factory;
// a custom function to consume data
public void consumeBatch(Consumer consumer, ConsumerRecords data){
data.forEach(r -> System.out.println(r.topic() + "_" + r.offset() + ": " + r.value()))
}
public void runConsumer() {
KafkaPollingTracker poll = factory
// configure consumer
.charValueConsumer()
.cluster("cluster1")
.group("somegroup")
.topic("mytopic")
// start the consumer in the background
.consume(this::consumeBatch, Duration.ofSeconds(1));
// Close when we need to stop consumption. With no explicit Bootique will
// close the consumer before the app exit
// poll.close();
}
```
## Streams Configuration
TODO