Skip to content

Commit 386512a

Browse files
committed
Docs.
Resolves #2239
1 parent 7951aa1 commit 386512a

File tree

2 files changed

+30
-18
lines changed

2 files changed

+30
-18
lines changed

spring-kafka-docs/src/main/asciidoc/index.adoc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,12 @@ The <<kafka,main chapter>> covers the core classes to develop a Kafka applicatio
4747

4848
include::kafka.adoc[]
4949

50+
include::retrytopic.adoc[]
51+
5052
include::streams.adoc[]
5153

5254
include::testing.adoc[]
5355

54-
include::retrytopic.adoc[]
55-
5656
[[tips-n-tricks]]
5757
== Tips, Tricks and Examples
5858

spring-kafka-docs/src/main/asciidoc/retrytopic.adoc

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ IMPORTANT: This is an experimental feature and the usual rule of no breaking API
55
Users are encouraged to try out the feature and provide feedback via GitHub Issues or GitHub discussions.
66
This is regarding the API only; the feature is considered to be complete, and robust.
77

8+
Version 2.9 changed the mechanism to bootstrap infrastructure beans; see <<retry-config>> for the two mechanisms that are now required to bootstrap the feature.
9+
10+
After these changes, we are intending to remove the experimental designation, probably in version 3.0.
11+
812
Achieving non-blocking retry / dlt functionality with Kafka usually requires setting up extra topics and creating and configuring the corresponding listeners.
913
Since 2.7 Spring for Apache Kafka offers support for that via the `@RetryableTopic` annotation and `RetryTopicConfiguration` class to simplify that bootstrapping.
1014

@@ -33,28 +37,27 @@ If one message's processing takes longer than the next message's back off period
3337
Also, for short delays (about 1s or less), the maintenance work the thread has to do, such as committing offsets, may delay the message processing execution.
3438
The precision can also be affected if the retry topic's consumer is handling more than one partition, because we rely on waking up the consumer from polling and having full pollTimeouts to make timing adjustments.
3539

36-
That being said, for consumers handling a single partition the message's processing should happen under 100ms after it's exact due time for most situations.
40+
That being said, for consumers handling a single partition the message's processing should occur approximately at its exact due time for most situations.
3741

3842
IMPORTANT: It is guaranteed that a message will never be processed before its due time.
3943

4044
===== Tuning the Delay Precision
4145

42-
The message's processing delay precision relies on two `ContainerProperties`: `ContainerProperties.pollTimeout` and `ContainerProperties.idlePartitionEventInterval`.
43-
Both properties will be automatically set in the retry topic and dlt's `ListenerContainerFactory` to one quarter of the smallest delay value for that topic, with a minimum value of 250ms and a maximum value of 5000ms.
44-
These values will only be set if the property has its default values - if you change either value yourself your change will not be overridden.
45-
This way you can tune the precision and performance for the retry topics if you need to.
46-
47-
NOTE: You can have separate `ListenerContainerFactory` instances for the main and retry topics - this way you can have different settings to better suit your needs, such as having a higher polling timeout setting for the main topics and a lower one for the retry topics.
46+
Starting with version 2.9, it is no longer necessary to tune the precision because a task scheduler is used to resume the partition and wake the consumer, if necessary.
4847

48+
[[retry-config]]
4949
==== Configuration
5050

51-
Starting with version 2.9, the `@EnableKafkaRetryTopic` annotation should be used in a `@Configuration` annotated class.
51+
Starting with version 2.9, for default configuration, the `@EnableKafkaRetryTopic` annotation should be used in a `@Configuration` annotated class.
5252
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>>.
5553

5654
NOTE: It is not necessary to also add `@EnableKafka`, if you add this annotation, because `@EnableKafkaRetryTopic` is meta-annotated with `@EnableKafka`.
5755

56+
Also, starting with that version, for more advanced configuration of the feature's components and global features, the `RetryTopicConfigurationSupport` class should be extended in a `@Configuration` class, and the appropriate methods overridden.
57+
For more details refer to <<retry-topic-global-settings>>.
58+
59+
IMPORTANT: Only one of the above techniques can be used, and only one `@Configuration` class can extend `RetryTopicConfigurationSupport`.
60+
5861
===== Using the `@RetryableTopic` annotation
5962

6063
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.
@@ -161,9 +164,9 @@ It's best to use a single `RetryTopicConfiguration` bean for configuration of su
161164
[[retry-topic-global-settings]]
162165
===== Configuring Global Settings and Features
163166

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+
Since 2.9, the previous bean overriding approach for configuring components has been removed (without deprecation, due to the aforementioned experimental nature of the API).
168+
This does not change the `RetryTopicConfiguration` beans approach - only infrastructure components' configurations.
169+
Now the `RetryTopicConfigurationSupport` class should be extended in a (single) `@Configuration` class, and the proper methods overridden.
167170
An example follows:
168171

169172
====
@@ -185,6 +188,15 @@ public class MyRetryTopicConfiguration extends RetryTopicConfigurationSupport {
185188
protected void manageNonBlockingFatalExceptions(List<Class<? extends Throwable>> nonBlockingFatalExceptions) {
186189
nonBlockingFatalExceptions.add(MyNonBlockingException.class);
187190
}
191+
192+
@Override
193+
protected void configureCustomizers(CustomizersConfigurer customizersConfigurer) {
194+
// Use the new 2.9 mechanism to avoid re-fetching the same records after a pause
195+
customizersConfigurer.customizeErrorHandler(eh -> {
196+
((DefaultErrorHandler) eh).setSeekAfterError(false);
197+
});
198+
}
199+
188200
}
189201
----
190202
====
@@ -629,7 +641,7 @@ As an example the following implementation, in addition to the standard suffix,
629641
----
630642
public class CustomRetryTopicNamesProviderFactory implements RetryTopicNamesProviderFactory {
631643
632-
@Override
644+
@Override
633645
public RetryTopicNamesProvider createRetryTopicNamesProvider(
634646
DestinationTopic.Properties properties) {
635647
@@ -728,7 +740,7 @@ In the latter the consumer ends the execution without forwarding the message.
728740
----
729741
730742
@RetryableTopic(dltProcessingFailureStrategy =
731-
DltStrategy.FAIL_ON_ERROR)
743+
DltStrategy.FAIL_ON_ERROR)
732744
@KafkaListener(topics = "my-annotated-topic")
733745
public void processMessage(MyPojo message) {
734746
// ... message processing
@@ -777,7 +789,7 @@ In this case after retrials are exhausted the processing simply ends.
777789
----
778790
779791
@RetryableTopic(dltProcessingFailureStrategy =
780-
DltStrategy.NO_DLT)
792+
DltStrategy.NO_DLT)
781793
@KafkaListener(topics = "my-annotated-topic")
782794
public void processMessage(MyPojo message) {
783795
// ... message processing

0 commit comments

Comments
 (0)