Skip to content

Commit

Permalink
Reverse the order of the approaches to show the simpler option first
Browse files Browse the repository at this point in the history
  • Loading branch information
guillermocalvo committed Jul 21, 2023
1 parent 0a57413 commit 1b75dae
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,12 @@ public void onApplicationEvent(BeforeKafkaStreamStart event) {

@Override
public StreamThreadExceptionResponse handle(Throwable exception) {
return StreamThreadExceptionResponse.REPLACE_THREAD;
if (exception instanceof MyException) {
return StreamThreadExceptionResponse.REPLACE_THREAD;
}
return StreamThreadExceptionResponse.SHUTDOWN_APPLICATION;
}
}
// end::imports[]
// end::clazz[]

interface MyException { }
20 changes: 10 additions & 10 deletions src/main/docs/guide/kafkaStreams/kafkaStreamExceptions.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,7 @@ There are three possible https://kafka.apache.org/28/javadoc/org/apache/kafka/st

TIP: You can find more details about this mechanism https://developer.confluent.io/tutorials/error-handling/confluent.html[here].

To implement your own handler, you can listen to the application event api:io.micronaut.configuration.kafka.streams.event.BeforeKafkaStreamStart[] and configure the streams with your own business logic:

[source,java]
----
include::{testskafkastreams}/uncaught/MyStreamsUncaughtExceptionHandler.java[tags=imports, indent=0]
include::{testskafkastreams}/uncaught/MyStreamsUncaughtExceptionHandler.java[tags=clazz, indent=0]
----

However, if you just want to take the same action every time, you can set the application property `kafka.streams.[STREAM-NAME].uncaught-exception-handler` to a valid action, such as `REPLACE_THREAD`.
If you just want to take the same action every time, you can set the application property `kafka.streams.[STREAM-NAME].uncaught-exception-handler` to a valid action, such as `REPLACE_THREAD`.

For example in `application-test.yml`:

Expand All @@ -24,3 +15,12 @@ kafka:
my-stream:
uncaught-exception-handler: REPLACE_THREAD
----

To implement your own handler, you can listen to the application event api:io.micronaut.configuration.kafka.streams.event.BeforeKafkaStreamStart[] and configure the streams with your own business logic:

[source,java]
----
include::{testskafkastreams}/uncaught/MyStreamsUncaughtExceptionHandler.java[tags=imports, indent=0]
include::{testskafkastreams}/uncaught/MyStreamsUncaughtExceptionHandler.java[tags=clazz, indent=0]
----

0 comments on commit 1b75dae

Please sign in to comment.