-
Notifications
You must be signed in to change notification settings - Fork 106
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add guide section to document the new feature
- Loading branch information
1 parent
eb12223
commit de8b0f3
Showing
3 changed files
with
54 additions
and
0 deletions.
There are no files selected for viewing
27 changes: 27 additions & 0 deletions
27
.../io/micronaut/configuration/kafka/streams/uncaught/MyStreamsUncaughtExceptionHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package io.micronaut.configuration.kafka.streams.uncaught; | ||
|
||
// tag::imports[] | ||
import io.micronaut.configuration.kafka.streams.event.BeforeKafkaStreamStart; | ||
import io.micronaut.context.annotation.Requires; | ||
import io.micronaut.context.event.ApplicationEventListener; | ||
import jakarta.inject.Singleton; | ||
import org.apache.kafka.streams.errors.StreamsUncaughtExceptionHandler; | ||
// end::imports[] | ||
|
||
@Requires(property = "do.not.enable", value = "just for documentation purposes") | ||
// tag::clazz[] | ||
@Singleton | ||
public class MyStreamsUncaughtExceptionHandler | ||
implements ApplicationEventListener<BeforeKafkaStreamStart>, StreamsUncaughtExceptionHandler { | ||
|
||
@Override | ||
public void onApplicationEvent(BeforeKafkaStreamStart event) { | ||
event.getKafkaStreams().setUncaughtExceptionHandler(this); | ||
} | ||
|
||
@Override | ||
public StreamThreadExceptionResponse handle(Throwable exception) { | ||
return StreamThreadExceptionResponse.REPLACE_THREAD; | ||
} | ||
} | ||
// end::imports[] |
26 changes: 26 additions & 0 deletions
26
src/main/docs/guide/kafkaStreams/kafkaStreamExceptions.adoc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
Since version 2.8.0, Kafka allows you to https://kafka.apache.org/28/javadoc/org/apache/kafka/streams/errors/StreamsUncaughtExceptionHandler.html[handle uncaught exceptions] that may be thrown from your streams. This handler must return the action that must be taken, depending on the thrown exception. | ||
|
||
There are three possible https://kafka.apache.org/28/javadoc/org/apache/kafka/streams/errors/StreamsUncaughtExceptionHandler.StreamThreadExceptionResponse.html[responses]: `REPLACE_THREAD`, `SHUTDOWN_CLIENT`, or `SHUTDOWN_APPLICATION`. | ||
|
||
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`. | ||
|
||
For example in `application-test.yml`: | ||
|
||
[source,yaml] | ||
---- | ||
kafka: | ||
streams: | ||
my-stream: | ||
uncaught-exception-handler: REPLACE_THREAD | ||
---- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters