mirror of
https://github.com/Dannecron/spring-boot-demo.git
synced 2025-12-26 00:32:34 +03:00
add schema validator
use ConfigurationProperties instead of Value for configuration
This commit is contained in:
@@ -5,7 +5,6 @@ import com.example.demo.services.kafka.Consumer
|
||||
import org.apache.kafka.clients.consumer.ConsumerConfig
|
||||
import org.apache.kafka.common.serialization.StringDeserializer
|
||||
import org.springframework.beans.factory.annotation.Autowired
|
||||
import org.springframework.beans.factory.annotation.Value
|
||||
import org.springframework.context.annotation.Bean
|
||||
import org.springframework.context.annotation.Configuration
|
||||
import org.springframework.kafka.config.ConcurrentKafkaListenerContainerFactory
|
||||
@@ -14,23 +13,18 @@ import org.springframework.kafka.core.DefaultKafkaConsumerFactory
|
||||
|
||||
@Configuration
|
||||
class KafkaConsumerConfig(
|
||||
@Value("\${kafka.bootstrap-servers}")
|
||||
val servers: String,
|
||||
@Value("\${kafka.consumer.group-id}")
|
||||
val consumerGroup: String,
|
||||
@Autowired val kafkaProperties: KafkaProperties
|
||||
) {
|
||||
@Bean
|
||||
fun consumer(
|
||||
@Autowired cityService: CityService,
|
||||
): Consumer = Consumer(
|
||||
cityService = cityService,
|
||||
)
|
||||
): Consumer = Consumer(cityService)
|
||||
|
||||
@Bean
|
||||
fun consumerFactory(): ConsumerFactory<String, String> {
|
||||
val configs = mapOf(
|
||||
ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG to servers,
|
||||
ConsumerConfig.GROUP_ID_CONFIG to consumerGroup,
|
||||
ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG to kafkaProperties.bootstrapServers,
|
||||
ConsumerConfig.GROUP_ID_CONFIG to kafkaProperties.consumer.groupId,
|
||||
ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG to StringDeserializer::class.java,
|
||||
ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG to StringDeserializer::class.java,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user