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
GH-2496: Reuse retry topic for maxInterval delay (#2497)
* GH-2496: Reuse retry topic for maxInterval delay
Resolves#2496
Created SameIntervalTopicReuseStrategy, used to keep retrying in the
same retry topic when the delays of the last retries are the same.
* GH-2496 Reference documentation typos.
* GH-2496: Deprecation of FixedDelayStrategy.
RetryTopic docs and code fixes and small refactorings.
* GH-2496: Restoring DestinationTopic.isSingleTopicRetry()
* GH-2496: Restoring DestinationTopic.Type.SINGLE_TOPIC_RETRY.
* GH-2496: Removal of "forRemoval" for FixedDelayStrategy
* GH-2496: Supressing deprecation warnings
* GH-2496 Ajusting new method isRetryTopic().
* GH-2496: Documentation and formatting
---------
Co-authored-by: João Guilherme de Souza Lima <[email protected]>
Copy file name to clipboardExpand all lines: spring-kafka-docs/src/main/asciidoc/index.adoc
+1-1
Original file line number
Diff line number
Diff line change
@@ -17,7 +17,7 @@ ifdef::backend-pdf[]
17
17
NOTE: This documentation is also available as https://docs.spring.io/spring-kafka/docs/{project-version}/reference/html/index.html[HTML].
18
18
endif::[]
19
19
20
-
(C) 2016 - 2022 VMware, Inc.
20
+
(C) 2016 - 2023 VMware, Inc.
21
21
22
22
Copies of this document may be made for your own use and for distribution to others, provided that you do not charge any fee for such copies and further provided that each copy contains this Copyright Notice, whether distributed in print or electronically.
Copy file name to clipboardExpand all lines: spring-kafka-docs/src/main/asciidoc/retrytopic.adoc
+114-37
Original file line number
Diff line number
Diff line change
@@ -146,7 +146,8 @@ public RetryTopicConfiguration myOtherRetryTopic(KafkaTemplate<String, MyOtherPo
146
146
----
147
147
====
148
148
149
-
NOTE: The retry topics' and dlt's consumers will be assigned to a consumer group with a group id that is the combination of the one with you provide in the `groupId` parameter of the `@KafkaListener` annotation with the topic's suffix. If you don't provide any they'll all belong to the same group, and rebalance on a retry topic will cause an unnecessary rebalance on the main topic.
149
+
NOTE: The retry topics' and dlt's consumers will be assigned to a consumer group with a group id that is the combination of the one with you provide in the `groupId` parameter of the `@KafkaListener` annotation with the topic's suffix.
150
+
If you don't provide any they'll all belong to the same group, and rebalance on a retry topic will cause an unnecessary rebalance on the main topic.
150
151
151
152
IMPORTANT: If the consumer is configured with an <<error-handling-deserializer,`ErrorHandlingDeserializer`>>, to handle deserilialization exceptions, it is important to configure the `KafkaTemplate` and its producer with a serializer that can handle normal objects as well as raw `byte[]` values, which result from deserialization exceptions.
152
153
The generic value type of the template should be `Object`.
@@ -401,39 +402,6 @@ If your back off policy requires delays with values bigger than that, adjust the
401
402
402
403
IMPORTANT: The first attempt counts against `maxAttempts`, so if you provide a `maxAttempts` value of 4 there'll be the original attempt plus 3 retries.
403
404
404
-
===== Single Topic Fixed Delay Retries
405
-
406
-
If you're using fixed delay policies such as `FixedBackOffPolicy` or `NoBackOffPolicy` you can use a single topic to accomplish the non-blocking retries.
407
-
This topic will be suffixed with the provided or default suffix, and will not have either the index or the delay values appended.
NOTE: The default behavior is to create separate retry topics for each attempt, appended with an index value: retry-0, retry-1, ..., retry-n.
665
+
Therefore, by default the number of retry topics is the configured `maxAttempts` minus 1.
666
+
667
+
You can <<retry-topics-and-dlt-suffixes,configure the suffixes>>, choose whether to append <<append-index-or-delay,the attempt index or delay>>, use a <<single-topic-fixed-delay,single retry topic when using fixed backoff>>, and use a <<single-topic-maxinterval-delay,single retry topic for the attempts with the maxInterval>> when using exponential backoffs.
668
+
669
+
[[retry-topics-and-dlt-suffixes]]
696
670
===== Retry Topics and Dlt Suffixes
697
671
698
672
You can specify the suffixes that will be used by the retry and dlt topics.
@@ -724,6 +698,7 @@ public RetryTopicConfiguration myRetryTopic(KafkaTemplate<String, MyOtherPojo> t
724
698
725
699
NOTE: The default suffixes are "-retry" and "-dlt", for retry topics and dlt respectively.
726
700
701
+
[[append-index-or-delay]]
727
702
===== Appending the Topic's Index or Delay
728
703
729
704
You can either append the topic's index or delay values after the suffix.
@@ -754,9 +729,108 @@ public RetryTopicConfiguration myRetryTopic(KafkaTemplate<String, MyPojo> templa
754
729
755
730
NOTE: The default behavior is to suffix with the delay values, except for fixed delay configurations with multiple topics, in which case the topics are suffixed with the topic's index.
756
731
732
+
[[single-topic-fixed-delay]]
733
+
===== Single Topic for Fixed Delay Retries
734
+
735
+
If you're using fixed delay policies such as `FixedBackOffPolicy` or `NoBackOffPolicy` you can use a single topic to accomplish the non-blocking retries.
736
+
This topic will be suffixed with the provided or default suffix, and will not have either the index or the delay values appended.
737
+
738
+
NOTE: `FixedDelayStrategy` is now deprecated, and will be replaced by `SameIntervalTopicReuseStrategy` in a future release.
public RetryTopicConfiguration myRetryTopic(KafkaTemplate<String, MyPojo> template) {
756
+
return RetryTopicConfigurationBuilder
757
+
.newInstance()
758
+
.fixedBackoff(3000)
759
+
.maxAttempts(5)
760
+
.useSingleTopicForFixedDelays()
761
+
.create(template);
762
+
}
763
+
----
764
+
====
765
+
766
+
NOTE: The default behavior is creating separate retry topics for each attempt, appended with their index value: retry-0, retry-1, ...
767
+
768
+
769
+
[[single-topic-maxinterval-delay]]
770
+
===== Single Topic for maxInterval Exponential Delay
771
+
772
+
If you're using exponential backoff policy (`ExponentialBackOffPolicy`), you can use a single retry topic to accomplish the non-blocking retries of the attempts whose delays are the configured `maxInterval`.
773
+
774
+
This "final" retry topic will be suffixed with the provided or default suffix, and will have either the index or the `maxInterval` value appended.
775
+
776
+
NOTE: By opting to use a single topic for the retries with the `maxInterval` delay, it may become more viable to configure an exponential retry policy that keeps retrying for a long time, because in this approach you do not need a large amount of topics.
777
+
778
+
The default behavior is to work with the number of retry topics equal to the configured `maxAttempts` minus 1 and, when using exponential backoff, the retry topics are suffixed with the delay values, with the last retry topic (corresponding to the `maxInterval` delay) being suffixed with an additional index.
779
+
780
+
For instance, when configuring the exponential backoff with `initialInterval=1000`, `multiplier=2`, and `maxInterval=16000`, in order to keep trying for one hour, one would need to configure `maxAttempts` as 229, and by default the needed retry topics would be:
781
+
782
+
* -retry-1000
783
+
* -retry-2000
784
+
* -retry-4000
785
+
* -retry-8000
786
+
* -retry-16000-0
787
+
* -retry-16000-1
788
+
* -retry-16000-2
789
+
* ...
790
+
* -retry-16000-224
791
+
792
+
When using the strategy that reuses the retry topic for the same intervals, in the same configuration above the needed retry topics would be:
public RetryTopicConfiguration myRetryTopic(KafkaTemplate<String, MyPojo> template) {
820
+
return RetryTopicConfigurationBuilder
821
+
.newInstance()
822
+
.exponentialBackoff(1000, 2, 16000)
823
+
.maxAttempts(230)
824
+
.useSingleTopicForSameIntervals()
825
+
.create(template);
826
+
}
827
+
----
828
+
====
829
+
757
830
===== Custom naming strategies
758
831
759
-
More complex naming strategies can be accomplished by registering a bean that implements `RetryTopicNamesProviderFactory`. The default implementation is `SuffixingRetryTopicNamesProviderFactory` and a different implementation can be registered in the following way:
832
+
More complex naming strategies can be accomplished by registering a bean that implements `RetryTopicNamesProviderFactory`.
833
+
The default implementation is `SuffixingRetryTopicNamesProviderFactory` and a different implementation can be registered in the following way:
760
834
761
835
====
762
836
[source, java]
@@ -836,7 +910,9 @@ The framework will configure and use a separate set of retry topics for each lis
836
910
837
911
==== Dlt Strategies
838
912
839
-
The framework provides a few strategies for working with DLTs. You can provide a method for DLT processing, use the default logging method, or have no DLT at all. Also you can choose what happens if DLT processing fails.
913
+
The framework provides a few strategies for working with DLTs.
914
+
You can provide a method for DLT processing, use the default logging method, or have no DLT at all.
915
+
Also you can choose what happens if DLT processing fails.
840
916
841
917
===== Dlt Processing Method
842
918
@@ -1045,7 +1121,8 @@ Use the `DestinationTopicResolver` interface if you need to weigh in these facto
1045
1121
[[change-kboe-logging-level]]
1046
1122
==== Changing KafkaBackOffException Logging Level
1047
1123
1048
-
When a message in the retry topic is not due for consumption, a `KafkaBackOffException` is thrown. Such exceptions are logged by default at `DEBUG` level, but you can change this behavior by setting an error handler customizer in the `ListenerContainerFactoryConfigurer` in a `@Configuration` class.
1124
+
When a message in the retry topic is not due for consumption, a `KafkaBackOffException` is thrown.
1125
+
Such exceptions are logged by default at `DEBUG` level, but you can change this behavior by setting an error handler customizer in the `ListenerContainerFactoryConfigurer` in a `@Configuration` class.
1049
1126
1050
1127
For example, to change the logging level to WARN you might add:
0 commit comments