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
Resolves#2226
Add RetryTopicConfigurationSupport
Add @EnableRetryTopic
Add KafkaBackOffManagerConfigurationSupport
Address code review comments
* Change deprecated constants for strings
* Remove deprecation suppressions
* Remove ApplicationContext and BeanFactory from constructors
* Change TaskExecutor shutdown logic to DisposableBean
Remove KafkaBackOffManagerConfigurationSupport
Move Task Executor logic to Timing Adjuster
Add unit tests
Enable managing fatal exceptions with a List
Create defaultFatalExceptionsList method in `ExceptionClassifier`
Change RetryTopicConfigurationSupport logic to provide a list instead of a configurer for non-blocking retries
Make provided TaskExecutor a bean
Add KafkaBackOffManagerConfigurer to RetryTopicConfigurationSupport
Add documentation
Review javadocs
Few other adjustments
Use JavaUtils instead of if statements
Add acceptIfInstanceOf to JavaUtils
Address PR review comments
Restore `ThreadPoolTaskExecutor` bean
Polishing per review comments.
Copy file name to clipboardExpand all lines: spring-kafka-docs/src/main/asciidoc/retrytopic.adoc
+89-75Lines changed: 89 additions & 75 deletions
Original file line number
Diff line number
Diff line change
@@ -48,6 +48,13 @@ NOTE: You can have separate `ListenerContainerFactory` instances for the main an
48
48
49
49
==== Configuration
50
50
51
+
Starting with version 2.9, the `@EnableKafkaRetryTopic` 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 feature's components and global features, the `RetryTopicConfigurationSupport` class should be extended in a `@Configuration` class, and the appropriate methods overridden.
54
+
For more details refer to <<retry-topic-global-settings>>.
55
+
56
+
NOTE: It is not necessary to also add `@EnableKafka`, if you add this annotation, because `@EnableKafkaRetryTopic` is meta-annotated with `@EnableKafka`.
57
+
51
58
===== Using the `@RetryableTopic` annotation
52
59
53
60
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.
@@ -76,7 +83,7 @@ public void processMessage(MyPojo message) {
76
83
----
77
84
====
78
85
79
-
NOTE: If you don't specify a kafkaTemplate name a bean with name `retryTopicDefaultKafkaTemplate` will be looked up.
86
+
NOTE: If you don't specify a kafkaTemplate name a bean with name `defaultRetryTopicKafkaTemplate` will be looked up.
80
87
If no bean is found an exception is thrown.
81
88
82
89
===== Using `RetryTopicConfiguration` beans
@@ -151,6 +158,40 @@ public KafkaTemplate<String, Object> kafkaTemplate() {
151
158
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
159
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
160
161
+
[[retry-topic-global-settings]]
162
+
===== Configuring Global Settings and Features
163
+
164
+
Since 2.9, the previous bean overriding approach for configuring components has been deprecated.
165
+
This does not change the `RetryTopicConfiguration` beans approach - only components' configurations.
166
+
Now the `RetryTopicConfigurationSupport` class should be extended in a `@Configuration` class, and the proper methods overridden.
167
+
An example follows:
168
+
169
+
====
170
+
[source, java]
171
+
----
172
+
173
+
@EnableKafka
174
+
@Configuration
175
+
public class MyRetryTopicConfiguration extends RetryTopicConfigurationSupport {
IMPORTANT: When using this configuration approach, the `@EnableKafkaRetryTopic` annotation should not be used to prevent context failing to start due to duplicated beans.
193
+
Use the simple `@EnableKafka` annotation instead.
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 `@Configuration` 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 `@Configuration` class that extends `RetryTopicConfigurationSupport`.
462
+
See <<retry-topic-global-settings>> for more details.
@@ -444,32 +482,21 @@ 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 `@Configuration` class that extends `RetryTopicConfigurationSupport` and add the exceptions you want to retry, along with the `BackOff` to be used.
486
+
The default `BackOff` is a `FixedBackOff` with no delay and 9 attempts.
487
+
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() {
618
+
return new CustomRetryTopicNamesProviderFactory();
619
+
}
620
+
};
596
621
}
597
622
----
598
623
====
@@ -811,21 +836,14 @@ public RetryTopicConfiguration myOtherRetryTopic(KafkaTemplate<Integer, MyPojo>
811
836
812
837
IMPORTANT: Since 2.8.3 you can use the same factory for retryable and non-retryable topics.
813
838
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:
839
+
If you need to revert the factory configuration behavior to prior 2.8.3, you can override the `configureRetryTopicConfigurer` method of a `@Configuration` class that extends `RetryTopicConfigurationSupport` as explained in <<retry-topic-global-settings>> and set `useLegacyFactoryConfigurer` to `true`, such as:
0 commit comments