Skip to content

Instantly share code, notes, and snippets.

@wpik
Last active March 27, 2019 14:19
Show Gist options
  • Select an option

  • Save wpik/56132d69e587f52ec66e5ee76aa4e71b to your computer and use it in GitHub Desktop.

Select an option

Save wpik/56132d69e587f52ec66e5ee76aa4e71b to your computer and use it in GitHub Desktop.
spring-kafka notes
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