Skip to content

Commit 049ef27

Browse files
GH-3880: The DefaultHandler resolves an incorrect value for the parameter annotated with @Header.
Fixes: #3880 Issue link: #3880 Add an documentation on how to correctly inject headers in default methods of class-level @KafkaListener. Because currently, The DefaultHandler resolve an incorrect value for the parameter annotated with @Header. also, the spring-kafka's intended usage is incompatiable with the design intent of the InvocationHandler, so spring-kafka cannot resolve this issue. Therefore, we will add documentation to prevent users from becoming confused. Signed-off-by: Sanghyeok An <[email protected]>
1 parent 6682837 commit 049ef27

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

spring-kafka-docs/src/main/antora/modules/ROOT/pages/kafka/receiving-messages/class-level-kafkalistener.adoc

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,25 @@ void listen(Object in, @Header(KafkaHeaders.RECORD_METADATA) ConsumerRecordMetad
6262
...
6363
}
6464
----
65+
66+
Also, this won't work as well.
67+
The `topic` is resolved to the `payload`.
68+
69+
[source, java]
70+
----
71+
@KafkaHandler(isDefault = true)
72+
public void listenDefault(String payload, @Header(KafkaHeaders.RECEIVED_TOPIC) String topic) {
73+
// payload.equals(topic) is True.
74+
...
75+
}
76+
----
77+
78+
If there are use cases in which discrete custom headers are required in a default method, use this:
79+
[source, java]
80+
----
81+
@KafkaHandler(isDefault = true)
82+
void listenDefault(String payload, @Headers Map<String, Object> headers) {
83+
Object myValue = headers.get("MyCustomHeader");
84+
...
85+
}
86+
----

0 commit comments

Comments
 (0)