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
Should fail bean registration when no method listeners are registered.
Current Behavior
@Component@KafkaListenerclassMyListener {
// There is no @KafkaHandler.publicvoidlisten1(Stringmessage) { ... }
// There is no @KafkaHandler.publicvoidlisten2(Stringmessage) { ... }
}
If a user registers a @KafkaListener as bean but there are no methods annotated with @KafkaHandler, spring-kafka creates MultiMethodKafkaListenerEndpoint without methods silently.
Later, After KafkaConsumer polls records, spring-kafka realizes that there are no available methods and just throws a runtime error.
In this case, user only becomes aware of the problem at runtime, even though the application is already malfunctioning.
I think It would be better to throw an IllegalStateException immediately when no methods annotated with @KafkaHandler are found so that the KafkaListener bean fails to be registered, following the fast-fail principle.
As-Is
There are no actions at all
To-Be
Throws an IllegalStateException immediately when no methods annotated with @KafkaHandler are found
Context
When I was writing test code for my PR, I encountered a situation where I only realized at runtime that the listener had not been properly registered.
Since I was not very familiar with this behavior, it took me some time to debug the issue.
I believe that new users of Spring Kafka might experience a similar problem.
If a KafkaListener is declared at the class level but no listener methods can be found,
I think it would be better to fail the Spring Boot application startup from a fast-fail perspective.
The text was updated successfully, but these errors were encountered:
Expected Behavior
Should fail bean registration when no method listeners are registered.
Current Behavior
If a user registers a
@KafkaListener
as bean but there are no methods annotated with@KafkaHandler
,spring-kafka
createsMultiMethodKafkaListenerEndpoint
without methods silently.Later, After
KafkaConsumer
polls records,spring-kafka
realizes that there are no available methods and just throws a runtime error.In this case, user only becomes aware of the problem at runtime, even though the application is already malfunctioning.
I think It would be better to throw an
IllegalStateException
immediately when no methods annotated with@KafkaHandler
are found so that theKafkaListener
bean fails to be registered, following thefast-fail
principle.IllegalStateException
immediately when no methods annotated with @KafkaHandler are foundContext
When I was writing test code for my PR, I encountered a situation where I only realized at runtime that the listener had not been properly registered.
Since I was not very familiar with this behavior, it took me some time to debug the issue.
I believe that new users of Spring Kafka might experience a similar problem.
If a
KafkaListener
is declared at the class level but no listener methods can be found,I think it would be better to fail the Spring Boot application startup from a
fast-fail
perspective.The text was updated successfully, but these errors were encountered: