Last active
March 27, 2019 14:19
-
-
Save wpik/56132d69e587f52ec66e5ee76aa4e71b to your computer and use it in GitHub Desktop.
spring-kafka notes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import org.springframework.boot.autoconfigure.kafka.ConcurrentKafkaListenerContainerFactoryConfigurer; | |
| import org.springframework.boot.context.properties.ConfigurationProperties; | |
| import org.springframework.context.annotation.Bean; | |
| import org.springframework.context.annotation.Configuration; | |
| import org.springframework.kafka.config.ConcurrentKafkaListenerContainerFactory; | |
| import org.springframework.kafka.core.ConsumerFactory; | |
| import org.springframework.kafka.listener.config.ContainerProperties; | |
| import java.util.regex.Pattern; | |
| @Configuration | |
| public class ManualConfiguration{ | |
| /** | |
| * This method will configure created factory with properties from environment. | |
| * @param configurer | |
| * @return | |
| */ | |
| @Bean | |
| public ConcurrentKafkaListenerContainerFactory<Object, Object> kafkaListenerContainerFactory( | |
| ConcurrentKafkaListenerContainerFactoryConfigurer configurer | |
| ) { | |
| ConcurrentKafkaListenerContainerFactory<Object, Object> factory = | |
| new ConcurrentKafkaListenerContainerFactory<>(); | |
| configurer.configure(factory, consumerFactory()); | |
| return factory; | |
| } | |
| @Bean | |
| public ConsumerFactory<Object, Object> consumerFactory() { | |
| return null; //create consumer factory here | |
| } | |
| /** | |
| * I we need, we can create properties class filled with values from environment. | |
| * @return | |
| */ | |
| @Bean | |
| @ConfigurationProperties(prefix = "spring.kafka.listener") | |
| ContainerProperties containerProperties() { | |
| return new ContainerProperties((Pattern) null); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment