jimmy_terra
jimmy_terra

Reputation: 1510

What happens to messages with no matching Listener in Spring-Kafka?

My understanding of the @KafkaListener is that messages are consumed by matching the listener method's argument type with the message type.

What happens to messages that do not have a matching listener?

Upvotes: 0

Views: 407

Answers (1)

Gary Russell
Gary Russell

Reputation: 174484

It's not clear what you mean. What leads you to believe that?

@KafkaListener on a Method means there is a consumer (listener container) for each method so all methods get all records (unless they are in the same consumer group or you assign partitions manually).

@KafkaListener on a Class means you have to annotate multiple methods with @KafkaHandler and the framework will find which handler method to invoke based on the deserialized payload; the value deserializer must be able to deserialize the expected multiple types.

You can designate exactly one @KafkaHandler as the default handler (which is invoked if there is no match) - usually with an Object parameter.

If there is no match and no default handler method, the record goes to the configured ErrorHandler.

The default error handler logs the failure, but you can add your own to do whatever you want.

Upvotes: 1

Related Questions