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
Topics can be configured with all that automagic goodness
Current Behavior
Topics are not part of auto configuration.
Context
Currently the topics to be produced to or consumed from are not part of the spring-boot auto configuration, meaning there's no way to create topics via configs or completely configure the @KafkaListener annotation as the topics property must always be specified, driving the topics value from config must be done with SpEL which can get a bit ugly when you're trying to consume from multiple topics.
Similarly configuring by topic serialization can get difficult to read.
I propose that this config should sit under spring.kafka.topics with the following functionality:
spring.kafka.topics:
create-topics: true # a way to disable automatic topic creation [boolean optional default=false]partitions: 2# defines the number of partitions to create topics with [numeric optional default=1]replicas: 2# defines the number of partitions to create topics with [numeric optional default=1]compact: true # defines compact cleanup policy to create topics with [boolean optional default=false]topic-properties: # allows `org.apache.kafka.clients.producer.ProducerConfig` values to be used for topic creation [map optional default={}]retention.ms: 720000sensor-events: # alias/user friendly name for topicname: ...-sensor-events # full topic name to consume from [string required]enabled: true # provides a way to stop consuming from this topic in config [boolean optional default=true]key-serializer: org.apache.kafka.common.serialization.ByteArraySerializer # configures the by-topic-serializervalue-serializer: io.confluent.kafka.serializers.KafkaAvroSerializer # configures the by-topic-serializerkey-deserializer: org.apache.kafka.common.serialization.ByteArrayDeserializer # configures the by-topic-deserializervalue-deserializer: io.confluent.kafka.serializers.KafkaAvroDeserializer # configures the by-topic-deserializerpartitions: 3# overwrite for default abovereplicas: 3# overwrite for default abovecompact: false # overwrite for default abovetopic-properties: # overwrite for default aboveretention.ms: 360000...-events:
name: ......
the serialisation configs could be cleaned up with Serde's potentially.
and the automatic generation of the byTopicKafkaTemplate has been useful for writing integration tests though I wasn't aware of DelegatingByTopicSerializer.java at the time which may be preferable.
This is still a WIP on my end and I still have questions, such as how best to integrate this with async retries and dead letter topics, ideally for my case I would have 1 topic for dead letters where the serialization of the messages mimics the source topic and the deserialization uses the source topic name from the headers to deserialize.
would love to hear thoughts or be told I've completely missed something that's already implemented 🙏
Introducing properties under spring.kafka.topic or spring.kafka.topics should be a Boot consideration, as all such configuration properties reside in Boot, not Spring Kafka. If we decide to provide these as Boot properties, we need to carefully evaluate which properties to add. Spring Boot typically selects important properties and offers customization options for others.
We noticed you're passing topic-specific serializers/deserializers in your configuration. However, the Kafka client doesn't provide a way to set ser/des like that. Spring Kafka's delegating serializer/deserializer is a higher-level abstraction that uses the appropriate ser/de at runtime based on the topic. Therefore, those properties likely can't be supported as presented, even if we support topic properties at the Boot level.
Cc @wilkinsona, What are your thoughts on this? If you believe this needs discussion on the Boot side, please feel free to transfer this issue to the Spring Boot repository. Thank you!
My first impression is that there's at least some overlap with spring-projects/spring-boot#39066. I think we can probably use that issue for now. It already contains a few different suggestions and we'll have to consider all of them to figure out the right way to proceed. @StephenFlavin please feel free to add a comment to spring-projects/spring-boot#39066 where you feel that it doesn't already capture your suggestions.
Expected Behavior
Topics can be configured with all that automagic goodness
Current Behavior
Topics are not part of auto configuration.
Context
Currently the topics to be produced to or consumed from are not part of the spring-boot auto configuration, meaning there's no way to create topics via configs or completely configure the
@KafkaListener
annotation as thetopics
property must always be specified, driving thetopics
value from config must be done with SpEL which can get a bit ugly when you're trying to consume from multiple topics.Similarly configuring by topic serialization can get difficult to read.
I propose that this config should sit under
spring.kafka.topics
with the following functionality:the serialisation configs could be cleaned up with Serde's potentially.
I've been able to get some of this done locally.
WIP Implementation:
My
@KafkaListener
is configured like thisand the automatic generation of the
byTopicKafkaTemplate
has been useful for writing integration tests though I wasn't aware ofDelegatingByTopicSerializer.java
at the time which may be preferable.This is still a WIP on my end and I still have questions, such as how best to integrate this with async retries and dead letter topics, ideally for my case I would have 1 topic for dead letters where the serialization of the messages mimics the source topic and the deserialization uses the source topic name from the headers to deserialize.
would love to hear thoughts or be told I've completely missed something that's already implemented 🙏
Apologies if I should be raising this in https://github.com/spring-projects/spring-boot
The text was updated successfully, but these errors were encountered: