diff --git a/spring-kafka-docs/src/main/antora/modules/ROOT/pages/retrytopic/features.adoc b/spring-kafka-docs/src/main/antora/modules/ROOT/pages/retrytopic/features.adoc index 963efa4dcc..3b4ac5bfc9 100644 --- a/spring-kafka-docs/src/main/antora/modules/ROOT/pages/retrytopic/features.adoc +++ b/spring-kafka-docs/src/main/antora/modules/ROOT/pages/retrytopic/features.adoc @@ -261,3 +261,41 @@ protected Consumer It is recommended that you use the provided resolvers when constructing the custom instance. +[[exc-based-custom-dlt-routing]] +== Routing of messages to custom DLTs based on thrown exceptions + +Starting with version 3.2.0, it's possible to route messages to custom DLTs based on the type of the exception, which has been thrown during their processing. +In order to do that, you need to specify the routing. +Routing customization consists of the specification of the additional destinations. +Destinations in turn consist of two settings: the `suffix` and `exceptions`. +When the exception type specified in `exceptions` has been thrown, the DLT containing the `suffix` will be considered as the target topic for the message before the general purpose DLT is considered. +Take a look at the examples: + +[source, java] +---- +@RetryableTopic(exceptionBasedDltRouting = { + @ExceptionBasedDltDestination( + suffix = "-deserialization", exceptions = {DeserializationException.class} + )} +) +@KafkaListener(topics = "my-annotated-topic") +public void processMessage(MyPojo message) { + // ... message processing +} +---- + +[source, java] +---- +@Bean +public RetryTopicConfiguration myRetryTopic(KafkaTemplate template) { + return RetryTopicConfigurationBuilder + .newInstance() + .dltRoutingRules(Map.of("-deserialization", Set.of(DeserializationException.class))) + .create(kafkaOperations) + .create(template); +} +---- + +`suffix` takes place before the general `dltTopicSuffix` in the custom DLT name. +Considering presented examples, the message, which caused the `DeserializationException` will be routed to the `my-annotated-topic-deserialization-dlt` instead of the `my-annotated-topic-dlt`. +Custom DLTs will be created following the same rules as stated in the xref:retrytopic/features.adoc#topics-autocreation[Topics AutoCreation]. \ No newline at end of file