Skip to content

ee08b397/EmbeddedKafkaTestLib

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build Status

EmbeddedKafkaTestLib

An in-memory embedded Kafka broker unit test library implemented with Spring Kafka. There are 4 clients can be used:

  • org.apache.kafka.clients.producer.Producer
  • org.apache.kafka.clients.consumer.Consumer
  • org.springframework.kafka.core.KafkaTemplate
  • org.springframework.kafka.listener.KafkaMessageListenerContainer

Depending on how the project to test is implemented, Producer and KafkaTemplate are message senders, and Consumer and KafkaMessageListenerContainer are message receivers. They can be used interchangeably.

How to Use

There is a sample unit test in com.bfm.libkafkatest.SampleTest. E.g., in com.bfm.libkafkatest.SampleTest.testProducerConsumer

KafkaTest<String, String> kafkaTest = new KafkaTestImpl<>();
Producer<String, String> producer = kafkaTest.getProducer(embeddedKafka);
Consumer<String, String> consumer = kafkaTest.getConsumer(embeddedKafka, Collections.singletonList(sampleTopic));

Created with the same embedded Kafka broker, the producer and consumer created here can be used for unit tests to send and receive messages.

About

Embedded Kafka Broker Unit Test Library via Spring Kafka

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages