Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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 2 months 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 (over 8 years ago)
- Default Branch: master
- Last Pushed: 2024-05-11T23:01:42.000Z (8 months ago)
- Last Synced: 2024-05-12T23:31:57.791Z (8 months ago)
- Topics: bootique, kafka, kafka-client
- Language: Java
- Homepage: http://bootique.io
- Size: 334 KB
- Stars: 4
- Watchers: 9
- Forks: 4
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[![build test deploy](https://github.com/bootique/bootique-kafka/actions/workflows/maven.yml/badge.svg)](https://github.com/bootique/bootique-kafka/actions/workflows/maven.yml)
[![Maven Central](https://img.shields.io/maven-central/v/io.bootique.kafka/bootique-kafka-client.svg?colorB=brightgreen)](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-clientio.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