Search in sources :

Example 1 with KafkaMessageListenerContainer

use of org.springframework.kafka.listener.KafkaMessageListenerContainer in project eventapis by kloiasoft.

the class EventApisFactory method operationsKafkaListenerContainerFactory.

@Bean("operationsKafkaListenerContainerFactory")
public KafkaListenerContainerFactory<KafkaMessageListenerContainer<String, Operation>> operationsKafkaListenerContainerFactory(ConsumerFactory<String, Operation> consumerFactory, PlatformTransactionManager platformTransactionManager) {
    AbstractKafkaListenerContainerFactory<KafkaMessageListenerContainer<String, Operation>, String, Operation> abstractKafkaListenerContainerFactory = new EventApisKafkaListenerContainerFactory(consumerFactory);
    RetryTemplate retryTemplate = new RetryTemplate();
    abstractKafkaListenerContainerFactory.setRetryTemplate(retryTemplate);
    abstractKafkaListenerContainerFactory.getContainerProperties().setPollTimeout(3000L);
    abstractKafkaListenerContainerFactory.getContainerProperties().setAckOnError(false);
    ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler();
    scheduler.setPoolSize(eventApisConfiguration.getEventBus().getConsumer().getOperationSchedulerPoolSize());
    scheduler.setBeanName("OperationsFactory-Scheduler");
    scheduler.initialize();
    abstractKafkaListenerContainerFactory.getContainerProperties().setScheduler(scheduler);
    // ThreadPoolTaskScheduler consumerScheduler = new ThreadPoolTaskScheduler();
    // consumerScheduler.setPoolSize(30);
    // consumerScheduler.setBeanName("OperationsFactory-ConsumerScheduler");
    // consumerScheduler.initialize();
    // 
    // abstractKafkaListenerContainerFactory.getContainerProperties().setConsumerTaskExecutor(consumerScheduler);
    abstractKafkaListenerContainerFactory.getContainerProperties().setAckMode(AbstractMessageListenerContainer.AckMode.RECORD);
    abstractKafkaListenerContainerFactory.getContainerProperties().setTransactionManager(platformTransactionManager);
    return abstractKafkaListenerContainerFactory;
}
Also used : RetryTemplate(org.springframework.retry.support.RetryTemplate) KafkaMessageListenerContainer(org.springframework.kafka.listener.KafkaMessageListenerContainer) Operation(com.kloia.eventapis.pojos.Operation) 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

Operation (com.kloia.eventapis.pojos.Operation)1 ConditionalOnMissingBean (org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean)1 FilterRegistrationBean (org.springframework.boot.web.servlet.FilterRegistrationBean)1 Bean (org.springframework.context.annotation.Bean)1 KafkaMessageListenerContainer (org.springframework.kafka.listener.KafkaMessageListenerContainer)1 RetryTemplate (org.springframework.retry.support.RetryTemplate)1 ThreadPoolTaskScheduler (org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler)1