shutdown all KafkaStream apps if one crashes
This commit is contained in:
parent
7a46ea7b75
commit
19bfe3a232
3 changed files with 8 additions and 3 deletions
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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(
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue