shutdown all KafkaStream apps if one crashes

This commit is contained in:
Adam 2022-03-12 01:39:19 +01:00
parent 7a46ea7b75
commit 19bfe3a232
3 changed files with 8 additions and 3 deletions

View file

@ -31,7 +31,7 @@ value class PlayerIndex(private val id: UInt) {
}
/** This is universally unique for every entity that has one, for the lifetime of a whole game. */
/** > This is universally unique for every entity that has one, for the lifetime of a whole game. */
@Serializable
@JvmInline
value class UnitNumber(private val id: UInt) {

View file

@ -156,7 +156,9 @@ internal class KafkatorioTopology(
props.setProperty(StreamsConfig.APPLICATION_ID_CONFIG, appId)
val streams = KafkaStreams(topology, props)
streams.setUncaughtExceptionHandler(StreamsExceptionHandler())
streams.setUncaughtExceptionHandler(StreamsExceptionHandler {
coroutineContext.job.cancel(CancellationException(cause = it))
})
val description: TopologyDescription = topology.describe()
println(

View file

@ -3,9 +3,12 @@ package dev.adamko.kafkatorio.processor
import org.apache.kafka.streams.errors.StreamsUncaughtExceptionHandler
import org.apache.kafka.streams.errors.StreamsUncaughtExceptionHandler.StreamThreadExceptionResponse
class StreamsExceptionHandler : StreamsUncaughtExceptionHandler {
class StreamsExceptionHandler(
val shutdown: (e: Throwable) -> Unit,
) : StreamsUncaughtExceptionHandler {
override fun handle(exception: Throwable): StreamThreadExceptionResponse {
exception.printStackTrace()
shutdown(exception)
return StreamThreadExceptionResponse.SHUTDOWN_APPLICATION
}
}