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#1817
* Fix flaky reactor test - add a delay to prevent canceling the consumer before offsets sent.
* Simplify for developers; support multiple enhancers; add coverage for repeated listeners.
* Docs for new changes.
* Doc that enhancer bean definitions must be static; add test.
Copy file name to clipboardExpand all lines: spring-kafka-docs/src/main/asciidoc/kafka.adoc
+29
Original file line number
Diff line number
Diff line change
@@ -1863,6 +1863,35 @@ void listen(Object in, @Header(KafkaHeaders.RECORD_METADATA) ConsumerRecordMetad
1863
1863
----
1864
1864
====
1865
1865
1866
+
[[kafkalistener-attrs]]
1867
+
===== `@KafkaListener` Attribute Modification
1868
+
1869
+
Starting with version 2.7.2, you can now programmatically modify annotation attributes before the container is created.
1870
+
To do so, add one or more `KafkaListenerAnnotationBeanPostProcessor.AnnotationEnhancer` to the application context.
1871
+
`AnnotationEnhancer` is a `BiFunction<Map<String, Object>, AnnotatedElement, Map<String, Object>` and must return a a map of attributes.
1872
+
The attribute values can contain SpEL and/or property placeholders; the enhancer is called before any resolution is performed.
1873
+
If more than one enhancer is present, and they implement `Ordered`, they will be invoked in order.
1874
+
1875
+
IMPORTANT: `AnnotationEnhancer` bean definitions must be declared `static` because they are required very early in the application context's lifecycle.
1876
+
1877
+
An example follows:
1878
+
1879
+
====
1880
+
[source, java]
1881
+
----
1882
+
@Bean
1883
+
public static AnnotationEnhancer groupIdEnhancer() {
1884
+
return (attrs, element) -> {
1885
+
attrs.put("groupId", attrs.get("id") + "." + (element instanceof Class
Copy file name to clipboardExpand all lines: spring-kafka/src/main/java/org/springframework/kafka/annotation/KafkaListenerAnnotationBeanPostProcessor.java
0 commit comments