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#2134
Also clean up parsing of `errorHandler` and `contentTypeConverter`.
**cherry-pick to 2.8.x**
* Polishing per review comments.
* Add info property to KafkaListener.
* Rebase; add since.
Copy file name to clipboardExpand all lines: spring-kafka-docs/src/main/asciidoc/kafka.adoc
+43
Original file line number
Diff line number
Diff line change
@@ -2315,6 +2315,18 @@ In addition, a `FilteringBatchMessageListenerAdapter` is provided, for when you
2315
2315
2316
2316
IMPORTANT: The `FilteringBatchMessageListenerAdapter` is ignored if your `@KafkaListener` receives a `ConsumerRecords<?, ?>` instead of `List<ConsumerRecord<?, ?>>`, because `ConsumerRecords` is immutable.
2317
2317
2318
+
Starting with version 2.8.4, you can override the listener container factory's default `RecordFilterStrategy` by using the `filter` property on the listener annotations.
@@ -5544,6 +5563,30 @@ It is disabled by default to avoid the (small) overhead of looking up the state
5544
5563
5545
5564
The `DefaultErrorHandler` and `DefaultAfterRollbackProcessor` support this feature.
5546
5565
5566
+
[[li-header]]
5567
+
===== Listener Info Header
5568
+
5569
+
In some cases, it is useful to be able to know which container a listener is running in.
5570
+
5571
+
Starting with version 2.8.4, you can now set the `listenerInfo` property on the listener container, or set the `info` attribute on the `@KafkaListener` annotation.
5572
+
Then, the container will add this in the `KafkaListener.LISTENER_INFO` header to all incoming messages; it can then be used in record interceptors, filters, etc., or in the listener itself.
When used in a `RecordInterceptor` or `RecordFilterStrategy` implementation, the header is in the consumer record as a byte array, converted using the `KafkaListenerAnnotationBeanPostProcessor` 's `charSet` property.
5587
+
5588
+
The header mappers also convert to `String` when creating `MessageHeaders` from the consumer record and never map this header on an outbound record.
Copy file name to clipboardExpand all lines: spring-kafka-docs/src/main/asciidoc/whats-new.adoc
+6
Original file line number
Diff line number
Diff line change
@@ -44,6 +44,12 @@ See <<batch-listener-conv-errors>> for more information.
44
44
`RecordFilterStrategy`, when used with batch listeners, can now filter the entire batch in one call.
45
45
See the note at the end of <<batch-listeners>> for more information.
46
46
47
+
The `@KafkaListener` annotation now has the `filter` attribute, to override the container factory's `RecordFilterStrategy` for just this listener.
48
+
49
+
The `@KafkaListener` annotation now the "info" attribute; this is used to populate the new listener container property `listenerInfo`.
50
+
This is then used to populate a `KafkaHeaders.LISTENER_INFO` header in each record which can be used in `RecordInterceptor`, `RecordFilterStrategy`, or the listener itself.
51
+
See <<li-header>> and <<alc-props,Abstract Listener Container Properties>> for more information.
Copy file name to clipboardExpand all lines: spring-kafka/src/main/java/org/springframework/kafka/annotation/KafkaListener.java
+28-1
Original file line number
Diff line number
Diff line change
@@ -1,5 +1,5 @@
1
1
/*
2
-
* Copyright 2016-2021 the original author or authors.
2
+
* Copyright 2016-2022 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
@@ -297,4 +297,31 @@
297
297
*/
298
298
Stringbatch() default"";
299
299
300
+
/**
301
+
* Set an {@link org.springframework.kafka.listener.adapter.RecordFilterStrategy} bean
302
+
* name to override the strategy configured on the container factory. If a SpEL
303
+
* expression is provided ({@code #{...}}), the expression can either evaluate to a
304
+
* {@link org.springframework.kafka.listener.adapter.RecordFilterStrategy} instance or
305
+
* a bean name.
306
+
* @return the error handler.
307
+
* @since 2.8.4
308
+
*/
309
+
Stringfilter() default"";
310
+
311
+
/**
312
+
* Static information that will be added as a header with key
313
+
* {@link org.springframework.kafka.support.KafkaHeaders#LISTENER_INFO}. This can be used, for example, in a
314
+
* {@link org.springframework.kafka.listener.RecordInterceptor}, {@link RecordFiorg.springframework.kafka.listener.adapter.RecordFilterStrategylterStrategy} or the listener itself, for
315
+
* any purposes.
316
+
* <p>
317
+
* SpEL {@code #{...}} and property place holders {@code ${...}} are supported, but it
318
+
* must resolve to a String or `byte[]`.
319
+
* <p>
320
+
* This header will be stripped out if an outbound record is created with the headers
Copy file name to clipboardExpand all lines: spring-kafka/src/main/java/org/springframework/kafka/annotation/KafkaListenerAnnotationBeanPostProcessor.java
+58-35
Original file line number
Diff line number
Diff line change
@@ -1,5 +1,5 @@
1
1
/*
2
-
* Copyright 2014-2021 the original author or authors.
2
+
* Copyright 2014-2022 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
0 commit comments