Reputation: 31
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.
Upvotes: 3
Views: 5815
Reputation: 1804
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);
Upvotes: 4