This is a Java unit test framework for testing scenarios requiring use of Apache Kafka
- Cluster support
- Fast startup
Version | Kafka version |
---|---|
1.0.x | 0.10.x |
2.0.0 | 0.11.x |
2.0.4 | 1.1.0 |
2.0.5 | 2.0.x |
2.1.0 | 2.1.x |
2.2.0 | 2.2.x |
2.3.0 | 2.3.x |
2.4.0 | 2.4.x |
2.5.0 | 2.5.x |
2.6.0 | 2.6.x |
2.7.0 | 2.7.x |
<dependency>
<groupId>org.mandas.kafka</groupId>
<artifactId>kafka-cluster-unit</artifactId>
<version>LATEST-VERSION</version>
<scope>test</scope>
</dependency>
@Rule
public KafkaClusterRule rule = new KafkaClusterRule(2, 10000, 11000); // This will manage 2 kafka brokers at port 10000-11000
KafkaCluster cluster = KafkaCluster.builder()
.withZookeeper("127.0.0.1", 10000, 11000)
.withBroker(1, "127.0.0.1", 10000, 11000)
.withBroker(2, "127.0.0.1", 10000, 11000)
.build();
cluster.start();
cluster.shutdown();
Properties p = new Properties();
p.put(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "earliest");
p.put(ConsumerConfig.GROUP_ID_CONFIG, "mygroup");
Consumer<String, String> consumer = cluster.consumer(p, new StringDeserializer(), new StringDeserializer());
Producer<String, String> producer = cluster.producer(new Properties(), new StringSerializer(), new StringSerializer());