Skip to content

Commit d38216b

Browse files
Add an CompositeRecordInterceptor to addRecordInterceptor API.
Signed-off-by: Sanghyeok An <[email protected]>
1 parent 7d94fca commit d38216b

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

spring-kafka/src/main/java/org/springframework/kafka/listener/AbstractMessageListenerContainer.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -477,9 +477,9 @@ public void setRecordInterceptor(@Nullable RecordInterceptor<K, V> recordInterce
477477

478478
/**
479479
* Add an interceptor to be called before calling the record listener
480-
* if the {@link AbstractMessageListenerContainer} is configured with a {@link CompositeRecordInterceptor}.
481-
* If a {@link CompositeRecordInterceptor} is not configured, the {@link AbstractMessageListenerContainer}
482-
* will not add {@link RecordInterceptor}.
480+
* If the {@link AbstractMessageListenerContainer} is not configured with a
481+
* {@link CompositeRecordInterceptor}, {@link CompositeRecordInterceptor} will be created internally
482+
* and configured to hold the added interceptor.
483483
* Does not apply to batch listeners.
484484
* @param recordInterceptor the interceptor.
485485
* @since 4.0
@@ -488,8 +488,12 @@ public void addRecordInterceptor(RecordInterceptor<K, V> recordInterceptor) {
488488
if (this.recordInterceptor instanceof CompositeRecordInterceptor<K, V> compositeRecordInterceptor) {
489489
compositeRecordInterceptor.addRecordInterceptor(recordInterceptor);
490490
}
491+
else if (this.recordInterceptor == null) {
492+
this.recordInterceptor = new CompositeRecordInterceptor<>(recordInterceptor);
493+
}
491494
else {
492-
this.logger.warn("Failed to add record interceptor.");
495+
this.recordInterceptor = new CompositeRecordInterceptor<>(this.recordInterceptor,
496+
recordInterceptor);
493497
}
494498
}
495499

0 commit comments

Comments
 (0)