-
Notifications
You must be signed in to change notification settings - Fork 1.6k
GH-3542: Adds the ability to add record interceptors instead of override them #3937
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
0c75fc7
5896ec2
7a6a385
7d94fca
d38216b
b84556e
defe8fb
21a7717
0d9010d
61c4ad2
0a6c020
d684913
7150d68
77b2051
327debf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,35 @@ IMPORTANT: If the interceptor mutates the record (by creating a new one), the `t | |
|
||
The `CompositeRecordInterceptor` and `CompositeBatchInterceptor` can be used to invoke multiple interceptors. | ||
|
||
Starting with version 4.0, `AbstractMessageListenerContainer` exposes `getRecordInterceptor()` as a public method. | ||
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. | ||
The following example shows how to do so: | ||
|
||
[source, java] | ||
---- | ||
public void configureRecordInterceptor(KafkaMessageListenerContainer<Integer, String> container) { | ||
CompositeRecordInterceptor compositeInterceptor; | ||
|
||
RecordInterceptor<Integer, String> previousInterceptor = container.getRecordInterceptor(); | ||
if (previousInterceptor instanceof CompositeRecordInterceptor interceptor) { | ||
compositeInterceptor = interceptor; | ||
} else { | ||
compositeInterceptor = new CompositeRecordInterceptor<>(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like just returned interceptor is not preserved in a new composite. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry for that. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please, look into my comment again . |
||
container.setRecordInterceptor(compositeInterceptor); | ||
} | ||
|
||
if (previousInterceptor != null) { | ||
compositeRecordInterceptor.addRecordInterceptor(previousInterceptor); | ||
} | ||
|
||
RecordInterceptor<Integer, String> recordInterceptor1 = new RecordInterceptor() {...}; | ||
RecordInterceptor<Integer, String> recordInterceptor2 = new RecordInterceptor() {...}; | ||
|
||
compositeInterceptor.addRecordInterceptor(recordInterceptor1); | ||
compositeInterceptor.addRecordInterceptor(recordInterceptor2); | ||
} | ||
---- | ||
|
||
By default, starting with version 2.8, when using transactions, the interceptor is invoked before the transaction has started. | ||
You can set the listener container's `interceptBeforeTx` property to `false` to invoke the interceptor after the transaction has started instead. | ||
Starting with version 2.9, this will apply to any transaction manager, not just `KafkaAwareTransactionManager`+++s+++. | ||
|
@@ -265,4 +294,3 @@ The listener containers implement `SmartLifecycle`, and `autoStartup` is `true` | |
The containers are started in a late phase (`Integer.MAX-VALUE - 100`). | ||
Other components that implement `SmartLifecycle`, to handle data from listeners, should be started in an earlier phase. | ||
The `- 100` leaves room for later phases to enable components to be auto-started after the containers. | ||
|
Uh oh!
There was an error while loading. Please reload this page.