Skip to content

Commit 7150d68

Browse files
Addressing PR review.
Signed-off-by: Sanghyeok An <[email protected]>
1 parent d684913 commit 7150d68

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

spring-kafka-docs/src/main/antora/modules/ROOT/pages/kafka/receiving-messages/message-listener-container.adoc

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,26 @@ The `CompositeRecordInterceptor` and `CompositeBatchInterceptor` can be used to
2424

2525
Starting with version 4.0, `AbstractMessageListenerContainer` exposes `getRecordInterceptor()` as a public method.
2626
If the returned interceptor is an instance of `CompositeRecordInterceptor`, additional `RecordInterceptor` instances can be added to it even after the container instance extending `AbstractMessageListenerContainer` has been created and a `RecordInterceptor` has already been configured.
27+
The following example shows how to do so:
28+
29+
[source, java]
30+
----
31+
public void configureRecordInterceptor(KafkaMessageListenerContainer<Integer, String> container) {
32+
CompositeRecordInterceptor compositeInterceptor;
2733
34+
if (container.getRecordInterceptor() instanceof CompositeRecordInterceptor interceptor) {
35+
compositeInterceptor = interceptor;
36+
} else {
37+
compositeInterceptor = new CompositeRecordInterceptor<>();
38+
}
39+
40+
RecordInterceptor<Integer, String> recordInterceptor1 = new RecordInterceptor() {...};
41+
RecordInterceptor<Integer, String> recordInterceptor2 = new RecordInterceptor() {...};
42+
43+
compositeInterceptor.addRecordInterceptor(recordInterceptor1);
44+
compositeInterceptor.addRecordInterceptor(recordInterceptor2);
45+
}
46+
----
2847

2948
By default, starting with version 2.8, when using transactions, the interceptor is invoked before the transaction has started.
3049
You can set the listener container's `interceptBeforeTx` property to `false` to invoke the interceptor after the transaction has started instead.

spring-kafka-docs/src/main/antora/modules/ROOT/pages/whats-new.adoc

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,5 @@ More details are available in xref:kafka/headers.adoc#multi-value-header[Support
8080
[[x40-add-record-interceptor]]
8181
=== Configure additional `RecordInterceptor`
8282

83-
The `KafkaMessageListenerContainer` and `ConcurrentMessageListenerContainer` support `getRecordInterceptor()`.
84-
If the returned interceptor is an instance of `CompositeRecordInterceptor`, additional `RecordInterceptor` instances can be added to it.
85-
More details are available in xref:kafka/receiving-messages/message-listener-container.adoc#message-listener-container[Message Listener Containers].
83+
Listener containers now support interceptor customization via `getRecordInterceptor()`.
84+
See the xref:kafka/receiving-messages/message-listener-container.adoc#message-listener-container[Message Listener Containers] section for details.

0 commit comments

Comments
 (0)