I'm using Spring Kafka with the the @EmbeddedKafka
annotation to start the Embedded kafka instance.
Dependency:
<dependency>
<groupId>org.springframework.kafka</groupId>
<artifactId>spring-kafka-test</artifactId>
<scope>test</scope>
</dependency>
And I've configured my application to connect to it:
spring:
kafka:
bootstrap-servers: ${spring.embedded.kafka.brokers}
I am successfully sending messages and consuming messages.
My problem is that the messages are retained somewhere and may appear in proceeding test runs. And the logs are printing these:
Successfully joined group with generation 117
The high generation number indicates that Kafka is retaining information between test reruns that i do not want.
How do I completely clean up Embedded Kafka and start fresh?
EDIT:
The issue I had was I was using Spring Profiles incorrectly. I had a custom annotation annotation with my embedded Kafka configuration. The problem was I was setting @ActiveProfiles("kafka")
in the compound annotation, and also setting @ActiveProfiles("dev")
in the actual test class. I've updated the compound annotation to this:
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
// @ActiveProfiles("kafka") REMOVED
@TestPropertySource(properties = "spring.kafka.bootstrap-servers=${spring.embedded.kafka.brokers}")
@EmbeddedKafka(/* config properties */)
public @interface CustomEmbeddedKafka{
}