I use Embedded Kafka to test send message to Kafka, when send failed, my code will re-send automatically, so I try to stop the Embedded Kafka then restart it during re-sending. But I don't know how to stop and start the Embedded Kafka.
            Asked
            
        
        
            Active
            
        
            Viewed 4,707 times
        
    1 Answers
3
            
            
        Kafka client code will manage resending messages in the event of failure. You should not need to write tests for that behaviour - by extension you could go down a real rabbit hole, testing core Java class behaviour etc.
However you can shut down and restart the broker with
embeddedKafkaBroker.getKafkaServers().forEach(KafkaServer::shutdown);
embeddedKafkaBroker.getKafkaServers().forEach(KafkaServer::awaitShutdown);
// Send messages
embeddedKafkaBroker.getKafkaServers().forEach(KafkaServer::startup);
 
    
    
        Chris
        
- 1,644
- 1
- 11
- 15
