Using generic container as @KafkaHandler
parameter?
#3943
Unanswered
Gyllsdorff
asked this question in
Q&A
Replies: 1 comment
-
@Service
class Handler {
@KafkaListener(topics = ["example"])
fun process(message: ConsumerRecord<String, Container<*>>) {
when (val data = message.value().data) {
is Foo -> logger.info { "Foo $data" }
is Bar -> logger.info { "Bar $data" }
else -> logger.warn { "Unknown data type: $data" }
}
}
} This is the best and least-hacky solution I have found so far but I would like to remove the dependency on the Spring Kafka |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
This might not be doable due to JVM:s generic type erasure, but I just want to check in case I am missing something obvious. :)
I have a kafka topic where the payload have a set of standard fields and a
data
object that can have 3 different shapes. The kafka message contains a header where the value is the type of the object in thedata
field.I can solve this by having separate concrete
Container
types for each data object type but I would like to use a generic container since the root object have a lot of fields in our production classes.The json deserialization works fine but the
DelegatingInvocableHandler.findHandlerForPayload
function seems to look for a handler with aContainer
parameter without the type so I get aNo method found for class com.example.Container
error orCannot convert from [com.example.Container] to [com.example.Container]
from theInvocableHandlerMethod
handler if I use@KafkaListener
directly on a function.Kotlin code example
Beta Was this translation helpful? Give feedback.
All reactions