Search in sources :

Example 1 with ConcurrentKafkaListenerContainerFactory

use of org.springframework.kafka.config.ConcurrentKafkaListenerContainerFactory in project loc-framework by lord-of-code.

the class LocKafkaAutoConfiguration method kafkaListenerContainerFactory.

@Bean(name = "kafkaListenerContainerFactory")
public ConcurrentKafkaListenerContainerFactory<?, ?> kafkaListenerContainerFactory(ConcurrentKafkaListenerContainerFactoryConfigurer configurer, ConsumerFactory<Object, Object> kafkaConsumerFactory) {
    ConcurrentKafkaListenerContainerFactory<Object, Object> factory = new ConcurrentKafkaListenerContainerFactory<>();
    ContainerProperties containerProperties = factory.getContainerProperties();
    containerProperties.setErrorHandler(new LocKafkaConsumerErrorHandler());
    factory.setRecordFilterStrategy(locMessageFilterStrategy());
    factory.setMessageConverter(recordMessageConverter());
    configurer.configure(factory, kafkaConsumerFactory);
    return factory;
}
Also used : ContainerProperties(org.springframework.kafka.listener.config.ContainerProperties) ConcurrentKafkaListenerContainerFactory(org.springframework.kafka.config.ConcurrentKafkaListenerContainerFactory) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) Bean(org.springframework.context.annotation.Bean)

Example 2 with ConcurrentKafkaListenerContainerFactory

use of org.springframework.kafka.config.ConcurrentKafkaListenerContainerFactory in project eventapis by kloiasoft.

the class EventApisFactory method eventsKafkaListenerContainerFactory.

@Bean({ "eventsKafkaListenerContainerFactory", "kafkaListenerContainerFactory" })
public ConcurrentKafkaListenerContainerFactory<String, PublishedEventWrapper> eventsKafkaListenerContainerFactory(EventMessageConverter eventMessageConverter, ConsumerFactory<String, PublishedEventWrapper> consumerFactory) {
    ConcurrentKafkaListenerContainerFactory<String, PublishedEventWrapper> factory = new ConcurrentKafkaListenerContainerFactory<>();
    factory.setConsumerFactory(consumerFactory);
    factory.setConcurrency(eventApisConfiguration.getEventBus().getConsumer().getEventConcurrency());
    factory.setMessageConverter(eventMessageConverter);
    factory.getContainerProperties().setPollTimeout(3000);
    ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler();
    scheduler.setPoolSize(eventApisConfiguration.getEventBus().getConsumer().getEventSchedulerPoolSize());
    scheduler.setBeanName("EventsFactory-Scheduler");
    scheduler.initialize();
    factory.getContainerProperties().setScheduler(scheduler);
    factory.getContainerProperties().setAckMode(AbstractMessageListenerContainer.AckMode.RECORD);
    return factory;
}
Also used : PublishedEventWrapper(com.kloia.eventapis.kafka.PublishedEventWrapper) ConcurrentKafkaListenerContainerFactory(org.springframework.kafka.config.ConcurrentKafkaListenerContainerFactory) ThreadPoolTaskScheduler(org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler) FilterRegistrationBean(org.springframework.boot.web.servlet.FilterRegistrationBean) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) Bean(org.springframework.context.annotation.Bean)

Aggregations

ConditionalOnMissingBean (org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean)2 Bean (org.springframework.context.annotation.Bean)2 ConcurrentKafkaListenerContainerFactory (org.springframework.kafka.config.ConcurrentKafkaListenerContainerFactory)2 PublishedEventWrapper (com.kloia.eventapis.kafka.PublishedEventWrapper)1 FilterRegistrationBean (org.springframework.boot.web.servlet.FilterRegistrationBean)1 ContainerProperties (org.springframework.kafka.listener.config.ContainerProperties)1 ThreadPoolTaskScheduler (org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler)1