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#1741
`ReplyingKafkaTemplate` enable send and receive with `Message<?>`.
- also fix ToC level for new chapter
- also polishing some tests for left over state
* Revert RetryTopicConfigurerTests
* Polish Kotlin Snippets; fix Javadoc.
* Doc Polishing.
The result is a `ListenableFuture` that is asynchronously populated with the result (or an exception, for a timeout).
549
551
The result also has a `sendFuture` property, which is the result of calling `KafkaTemplate.send()`.
550
552
You can use this future to determine the result of the send operation.
@@ -762,6 +764,57 @@ These header names are used by the `@KafkaListener` infrastructure to route the
762
764
Starting with version 2.3, you can customize the header names - the template has 3 properties `correlationHeaderName`, `replyTopicHeaderName`, and `replyPartitionHeaderName`.
763
765
This is useful if your server is not a Spring application (or does not use the `@KafkaListener`).
764
766
767
+
[[exchanging-messages]]
768
+
====== Request/Reply with `Message<?>` s
769
+
770
+
Version 2.7 added methods to the `ReplyingKafkaTemplate` to send and receive `spring-messaging` 's `Message<?>` abstraction:
These will use the template's default `replyTimeout`, there are also overloaded versions that can take a timeout in the method call.
783
+
784
+
Use the first method if the consumer's `Deserializer` or the template's `MessageConverter` can convert the payload without any additional information, either via configuration or type metadata in the reply message.
785
+
786
+
Use the second method if you need to provide type information for the return type, to assist the message converter.
787
+
This also allows the same template to receive different types, even if there is no type metadata in the replies, such as when the server side is not a Spring application.
Copy file name to clipboardExpand all lines: spring-kafka-docs/src/main/asciidoc/retrytopic.adoc
+23-23Lines changed: 23 additions & 23 deletions
Original file line number
Diff line number
Diff line change
@@ -1,13 +1,13 @@
1
1
[[retry-topic]]
2
-
== Non-Blocking Retries
2
+
===Non-Blocking Retries
3
3
4
4
IMPORTANT: This is an experimental feature and the usual rule of no breaking API changes does not apply to this feature until the experimental designation is removed.
5
5
Users are encouraged to try out the feature and provide feedback via GitHub Issues or GitHub discussions.
6
6
7
7
Achieving non-blocking retry / dlt functionality with Kafka usually requires setting up extra topics and creating and configuring the corresponding listeners.
8
8
Since 2.7 Spring for Apache Kafka offers support for that via the `@RetryableTopic` annotation and `RetryTopicConfiguration` class to simplify that bootstrapping.
9
9
10
-
=== How The Pattern Works
10
+
==== How The Pattern Works
11
11
12
12
If message processing fails, the message is forwarded to a retry topic with a back off timestamp.
13
13
The retry topic consumer then checks the timestamp and if it's not due it pauses the consumption for that topic's partition.
@@ -23,9 +23,9 @@ IMPORTANT: You can set the `AckMode` mode you prefer, but `RECORD` is suggested.
23
23
24
24
IMPORTANT: At this time this functionality doesn't support class level `@KafkaListener` annotations
25
25
26
-
=== Back Off Delay Precision
26
+
==== Back Off Delay Precision
27
27
28
-
==== Overview and Guarantees
28
+
===== Overview and Guarantees
29
29
30
30
All message processing and backing off is handled by the consumer thread, and, as such, delay precision is guaranteed on a best-effort basis.
31
31
If one message's processing takes longer than the next message's back off period for that consumer, the next message's delay will be higher than expected.
@@ -36,7 +36,7 @@ That being said, for consumers handling a single partition the message's process
36
36
37
37
IMPORTANT: It is guaranteed that a message will never be processed before its due time.
38
38
39
-
==== Tuning the Delay Precision
39
+
===== Tuning the Delay Precision
40
40
41
41
The message's processing delay precision relies on two `ContainerProperties`: `ContainerProperties.pollTimeout` and `ContainerProperties.idlePartitionEventInterval`.
42
42
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.
@@ -45,9 +45,9 @@ This way you can tune the precision and performance for the retry topics if you
45
45
46
46
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.
47
47
48
-
=== Configuration
48
+
==== Configuration
49
49
50
-
==== Using the `@RetryableTopic` annotation
50
+
===== Using the `@RetryableTopic` annotation
51
51
52
52
To configure the retry topic and dlt for a `@KafkaListener` annotated method, you just have to add the `@RetryableTopic` annotation to it and Spring Kafka will bootstrap all the necessary topics and consumers with the default configurations.
53
53
@@ -78,7 +78,7 @@ public void processMessage(MyPojo message) {
78
78
NOTE: If you don't specify a kafkaTemplate name a bean with name `retryTopicDefaultKafkaTemplate` will be looked up.
79
79
If no bean is found an exception is thrown.
80
80
81
-
==== Using `RetryTopicConfiguration` beans
81
+
===== Using `RetryTopicConfiguration` beans
82
82
83
83
You can also configure the non-blocking retry support by creating `RetryTopicConfiguration` beans in a `@Configuration` annotated class.
84
84
@@ -126,11 +126,11 @@ public RetryTopicConfiguration myOtherRetryTopic(KafkaTemplate<String, MyOtherPo
126
126
127
127
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.
128
128
129
-
=== Features
129
+
==== Features
130
130
131
131
Most of the features are available both for the `@RetryableTopic` annotation and the `RetryTopicConfiguration` beans.
132
132
133
-
==== BackOff Configuration
133
+
===== BackOff Configuration
134
134
135
135
The BackOff configuration relies on the `BackOffPolicy` interface from the `Spring Retry` project.
136
136
@@ -187,7 +187,7 @@ NOTE: The default backoff policy is FixedBackOffPolicy with a maximum of 3 attem
187
187
188
188
IMPORTANT: The first attempt counts against the maxAttempts, so if you provide a maxAttempts value of 4 there'll be the original attempt plus 3 retries.
189
189
190
-
==== Single Topic Fixed Delay Retries
190
+
===== Single Topic Fixed Delay Retries
191
191
192
192
If you're using fixed delay policies such as `FixedBackOffPolicy` or `NoBackOffPolicy` you can use a single topic to accomplish the non-blocking retries.
193
193
This topic will be suffixed with the provided or default suffix, and will not have either the index or the delay values appended.
@@ -220,7 +220,7 @@ public RetryTopicConfiguration myRetryTopic(KafkaTemplate<String, MyPojo> templa
220
220
221
221
NOTE: The default behavior is creating separate retry topics for each attempt, appended with their index value: retry-0, retry-1, ...
222
222
223
-
==== Global timeout
223
+
===== Global timeout
224
224
225
225
You can set the global timeout for the retrying process.
226
226
If that time is reached, the next time the consumer throws an exception the message goes straight to the DLT, or just ends the processing if no DLT is available.
@@ -252,7 +252,7 @@ public RetryTopicConfiguration myRetryTopic(KafkaTemplate<String, MyPojo> templa
252
252
253
253
NOTE: The default is having no timeout set, which can also be achieved by providing -1 as the timout value.
254
254
255
-
==== Exception Classifier
255
+
===== Exception Classifier
256
256
257
257
You can specify which exceptions you want to retry on and which not to.
258
258
You can also set it to traverse the causes to lookup nested exceptions.
@@ -284,7 +284,7 @@ public RetryTopicConfiguration myRetryTopic(KafkaTemplate<String, MyOtherPojo> t
284
284
285
285
NOTE: The default behavior is retrying on all exceptions and not traversing causes.
286
286
287
-
==== Include and Exclude Topics
287
+
===== Include and Exclude Topics
288
288
289
289
You can decide which topics will and will not be handled by a `RetryTopicConfiguration` bean via the .includeTopic(String topic), .includeTopics(Collection<String> topics) .excludeTopic(String topic) and .excludeTopics(Collection<String> topics) methods.
290
290
@@ -312,7 +312,7 @@ public RetryTopicConfiguration myOtherRetryTopic(KafkaTemplate<Integer, MyPojo>
312
312
NOTE: The default behavior is to include all topics.
313
313
314
314
315
-
==== Topics AutoCreation
315
+
===== Topics AutoCreation
316
316
317
317
Unless otherwise specified the framework will auto create the required topics using `NewTopic` beans that are consumed by the `KafkaAdmin` bean.
318
318
You can specify the number of partitions and the replication factor with which the topics will be created, and you can turn this feature off.
@@ -357,7 +357,7 @@ public RetryTopicConfiguration myOtherRetryTopic(KafkaTemplate<Integer, MyPojo>
357
357
NOTE: By default the topics are autocreated with one partition and a replication factor of one.
358
358
359
359
360
-
=== Topic Naming
360
+
==== Topic Naming
361
361
362
362
Retry topics and DLT are named by suffixing the main topic with a provided or default value, appended by either the delay or index for that topic.
You can specify the suffixes that will be used by the retry and dlt topics.
373
373
@@ -398,7 +398,7 @@ public RetryTopicConfiguration myRetryTopic(KafkaTemplate<String, MyOtherPojo> t
398
398
399
399
NOTE: The default suffixes are "-retry" and "-dlt", for retry topics and dlt respectively.
400
400
401
-
==== Appending the Topic's Index or Delay
401
+
===== Appending the Topic's Index or Delay
402
402
403
403
You can either append the topic's index or delay values after the suffix.
404
404
@@ -428,11 +428,11 @@ public RetryTopicConfiguration myRetryTopic(KafkaTemplate<String, MyPojo> templa
428
428
429
429
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.
430
430
431
-
=== Dlt Strategies
431
+
==== Dlt Strategies
432
432
433
433
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.
434
434
435
-
==== Dlt Processing Method
435
+
===== Dlt Processing Method
436
436
437
437
You can specify the method used to process the Dlt for the topic, as well as the behavior if that processing fails.
438
438
@@ -487,7 +487,7 @@ public class MyCustomDltProcessor {
487
487
488
488
NOTE: If no DLT handler is provided, the default RetryTopicConfigurer.LoggingDltListenerHandlerMethod is used.
489
489
490
-
==== Dlt Failure Behavior
490
+
===== Dlt Failure Behavior
491
491
492
492
Should the Dlt processing fail, there are two possible behaviors available: `ALWAYS_RETRY_ON_ERROR` and `FAIL_ON_ERROR`.
493
493
@@ -521,7 +521,7 @@ public RetryTopicConfiguration myRetryTopic(KafkaTemplate<Integer, MyPojo> templ
521
521
522
522
NOTE: The default behavior is to `ALWAYS_RETRY_ON_ERROR`.
523
523
524
-
==== Configuring No Dlt
524
+
===== Configuring No Dlt
525
525
526
526
The framework also provides the possibility of not configuring a DLT for the topic.
527
527
In this case after retrials are exhausted the processing simply ends.
@@ -551,7 +551,7 @@ public RetryTopicConfiguration myRetryTopic(KafkaTemplate<Integer, MyPojo> templ
551
551
====
552
552
553
553
554
-
=== Specifying a ListenerContainerFactory
554
+
==== Specifying a ListenerContainerFactory
555
555
556
556
By default the RetryTopic configuration will use the provided factory from the `@KafkaListener` annotation, but you can specify a different one to be used to create the retry topic and dlt listener containers.
0 commit comments