You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It`s no a very successful or useful for now but want to ask advises pros/cons to this staff
Maybe there is way to create single kafka per tests but I miss it
Or etc
code
@Mojo(name ="start-kafka-broker")
classStartKafkaBrokerMojo(): AbstractMojo() {
@Parameter(defaultValue ="9092")
val kafkaPort:Int=29092
@Parameter(defaultValue ="2181")
val zookeeperPort:Int=22181
@Throws(MojoExecutionException::class, MojoFailureException::class)
overridefunexecute() {
try {
log.info("Starting Zookeeper on port $zookeeperPort and Kafka broker on port $kafkaPort")
KafkaHandler.start(zookeeperPort, kafkaPort)
} catch (e:Exception) {
log.error("Failed to start Kafka broker", e)
throwMojoExecutionException("Failed to start Kafka broker")
}
}
}
@Mojo(name ="stop-kafka-broker")
classStopKafkaBrokerMojo : AbstractMojo() {
@Parameter(defaultValue ="29092")
val kafkaPort:Int=29092
@Parameter(defaultValue ="22181")
val zookeeperPort:Int=22181
@Throws(MojoExecutionException::class, MojoFailureException::class)
overridefunexecute() {
log.info("Attempting to stop the Kafka broker")
KafkaHandler.stop()
}
}
object KafkaHandler {
privatelateinitvar zookeeper:TestingServerprivatelateinitvar kafkaServer:KafkaServerStartableprivatelateinitvar kafkaLogDir:PathprivatefunbuildKafkaConfig(zookeeperQuorum:String, kafkaPort:Int): KafkaConfig {
kafkaLogDir =Files.createTempDirectory("kafka_maven")
val props =Properties().apply {
put("port", "$kafkaPort")
put("broker.id", "1")
put("log.dirs", kafkaLogDir.toAbsolutePath().toString())
put("zookeeper.connect", zookeeperQuorum)
}
returnKafkaConfig(props)
}
funstart(zookeeperPort:Int, kafkaPort:Int) {
zookeeper =TestingServer(zookeeperPort, true)
val zookeeperConnectionString = zookeeper.getConnectString()
val kafkaConfig = buildKafkaConfig(zookeeperConnectionString, kafkaPort)
kafkaServer =KafkaServerStartable(kafkaConfig)
kafkaServer.startup()
}
funstop() {
try {
kafkaServer.shutdown()
zookeeper.close()
if (Files.exists(kafkaLogDir)) {
Files.walkFileTree(kafkaLogDir, object:SimpleFileVisitor<Path>() {
@Throws(IOException::class)
overridefunvisitFile(file:Path, attrs:BasicFileAttributes): FileVisitResult {
Files.deleteIfExists(file)
returnFileVisitResult.CONTINUE
}
@Throws(IOException::class)
overridefunpostVisitDirectory(dir:Path, exc:IOException?): FileVisitResult {
Files.deleteIfExists(dir)
returnFileVisitResult.CONTINUE
}
})
}
} catch (e:Exception) {
e.printStackTrace()
}
}
}
The text was updated successfully, but these errors were encountered:
I would say this goes out of scope of this project.
Perhaps better to ask for such a functionality in Apache Kafka community.
Although it isn't clear why would one need to have an embedded Kafka in the plugin since it is going to be semantically the same as have a standalone Kafka Broker...
Maybe will be good idea to put "embedded kafka" on to separated maven/gradle plugin
it can allow creation single kafka node per integration test phase
I`m trying to put 1.1.0 kafka to the
https://github.com/charithe/kafka-maven-plugin
It`s no a very successful or useful for now but want to ask advises pros/cons to this staff
Maybe there is way to create single kafka per tests but I miss it
Or etc
code
The text was updated successfully, but these errors were encountered: