You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: spring-kafka-docs/src/main/asciidoc/retrytopic.adoc
+89-74Lines changed: 89 additions & 74 deletions
Original file line number
Diff line number
Diff line change
@@ -48,6 +48,11 @@ NOTE: You can have separate `ListenerContainerFactory` instances for the main an
48
48
49
49
==== Configuration
50
50
51
+
IMPORTANT: Since 2.9, the `@EnableRetryTopic` annotation should be used in a `@Configuration` annotated class.
52
+
This enables the feature to bootstrap properly and gives access to injecting some of the feature's components to be looked up at runtime.
53
+
Also, to configure the components and global features, the `RetryTopicConfigurationSupport` class should be extended and imported in a `@Configuration` class.
54
+
For more details refer to <<retry-topic-global-settings>>.
55
+
51
56
===== Using the `@RetryableTopic` annotation
52
57
53
58
To configure the retry topic and dlt for a `@KafkaListener` annotated method, you just have to add the `@RetryableTopic` annotation to it and Spring for Apache Kafka will bootstrap all the necessary topics and consumers with the default configurations.
@@ -151,6 +156,42 @@ public KafkaTemplate<String, Object> kafkaTemplate() {
151
156
IMPORTANT: Multiple `@KafkaListener` annotations can be used for the same topic with or without manual partition assignment along with non-blocking retries, but only one configuration will be used for a given topic.
152
157
It's best to use a single `RetryTopicConfiguration` bean for configuration of such topics; if multiple `@RetryableTopic` annotations are being used for the same topic, all of them should have the same values, otherwise one of them will be applied to all of that topic's listeners and the other annotations' values will be ignored.
153
158
159
+
[[retry-topic-global-settings]]
160
+
===== Configuring Global Settings and Features
161
+
162
+
Since 2.9, the previous bean-based configuration approach has been deprecated.
163
+
Instead, the `RetryTopicConfigurationSupport` class should be extended, the proper methods overridden, and imported in a `@Configuration` annotated class.
164
+
An example follows:
165
+
166
+
====
167
+
[source, java]
168
+
----
169
+
170
+
@EnableKafka
171
+
@Import(MyRetryTopicConfiguration.class)
172
+
@Configuration
173
+
public class KafkaConfiguration {
174
+
}
175
+
176
+
public class MyRetryTopicConfiguration extends RetryTopicConfigurationSupport {
NOTE: When using this approach, the `@EnableRetryTopic` annotation is not necessary.
194
+
154
195
==== Features
155
196
156
197
Most of the features are available both for the `@RetryableTopic` annotation and the `RetryTopicConfiguration` beans.
@@ -315,24 +356,22 @@ NOTE: The default behavior is retrying on all exceptions and not traversing caus
315
356
316
357
Since 2.8.3 there's a global list of fatal exceptions which will cause the record to be sent to the DLT without any retries.
317
358
See <<default-eh>> for the default list of fatal exceptions.
318
-
You can add or remove exceptions to and from this list with:
359
+
You can add or remove exceptions to and from this list by overriding the `configureNonBlockingRetries` method in a class that extends `RetryTopicConfigurationSupport`.
360
+
See <<retry-topic-global-settings>> for more information.
NOTE: To disable fatal exceptions' classification, clear the default list using the `setClassifications` method in `DefaultDestinationTopicResolver`.
374
+
NOTE: To disable fatal exceptions' classification, just clear the provided list.
336
375
337
376
338
377
===== Include and Exclude Topics
@@ -419,19 +458,18 @@ This is to avoid creation of excessively large messages (due to the stack trace
419
458
420
459
See <<dlpr-headers>> for more information.
421
460
422
-
To reconfigure the framework to use different settings for these properties, replace the standard `DeadLetterPublishingRecovererFactory` bean by adding a `recovererCustomizer`:
461
+
To reconfigure the framework to use different settings for these properties, configure a `DeadLetterPublishingRecoverer` customizer by overriding the `configureCustomizers` method in a class that extends `RetryTopicConfigurationSupport`.
462
+
See <<retry-topic-global-settings>> for more details.
@@ -444,32 +482,22 @@ Starting with version 2.8.4, if you wish to add custom headers (in addition to t
444
482
Starting in 2.8.4 you can configure the framework to use both blocking and non-blocking retries in conjunction.
445
483
For example, you can have a set of exceptions that would likely trigger errors on the next records as well, such as `DatabaseAccessException`, so you can retry the same record a few times before sending it to the retry topic, or straight to the DLT.
446
484
447
-
To configure blocking retries you just need to add the exceptions you want to retry through the `addRetryableExceptions` method in the `ListenerContainerFactoryConfigurer` bean as follows.
448
-
The default policy is `FixedBackOff`, with nine retries and no delay between them.
449
-
Optionally, you can provide your own back off policy.
485
+
To configure blocking retries, override the `configureBlockingRetries` method in a class that extends `RetryTopicConfigurationSupport` and add the exceptions you want to retry, along with the `BackOff` to be used.
486
+
Then `@Import` this subclass in a `@Configuration` class.
487
+
The default `BackOff` is a `FixedBackOff` with no delay and 9 attempts.
488
+
See <<retry-topic-global-settings>> for more information.
If you need to further tune the exception classification, you can set your own `Map` of classifications through the `ListenerContainerFactoryConfigurer.setErrorHandlerCustomizer()` method, such as:
public RetryTopicNamesProviderFactory retryTopicNamesProviderFactory() {
619
+
return new CustomRetryTopicNamesProviderFactory();
620
+
}
621
+
};
596
622
}
597
623
----
598
624
====
@@ -811,21 +837,14 @@ public RetryTopicConfiguration myOtherRetryTopic(KafkaTemplate<Integer, MyPojo>
811
837
812
838
IMPORTANT: Since 2.8.3 you can use the same factory for retryable and non-retryable topics.
813
839
814
-
If you need to revert the factory configuration behavior to prior 2.8.3, you can replace the standard `RetryTopicConfigurer` bean and set `useLegacyFactoryConfigurer` to `true`, such as:
840
+
If you need to revert the factory configuration behavior to prior 2.8.3, you can override the `configureRetryTopicConfigurer` method of a class that extends `RetryTopicConfigurationSupport` as explained in <<retry-topic-global-settings>> and set `useLegacyFactoryConfigurer` to `true`, such as:
0 commit comments