org.springframework.kafka.config.ConcurrentKafkaListenerContainerFactory

Here are the examples of the java api org.springframework.kafka.config.ConcurrentKafkaListenerContainerFactory taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

79 Examples 7

19 View Source File : KafkaAutoConfigurationTests.java
License : Apache License 2.0
Project Creator : yuanmabiji

@Test
public void testConcurrentKafkaListenerContainerFactoryWithCustomAfterRollbackProcessor() {
    this.contextRunner.withUserConfiguration(AfterRollbackProcessorConfiguration.clreplaced).run((context) -> {
        ConcurrentKafkaListenerContainerFactory<?, ?> factory = context.getBean(ConcurrentKafkaListenerContainerFactory.clreplaced);
        DirectFieldAccessor dfa = new DirectFieldAccessor(factory);
        replacedertThat(dfa.getPropertyValue("afterRollbackProcessor")).isSameAs(context.getBean("afterRollbackProcessor"));
    });
}

19 View Source File : KafkaAutoConfigurationTests.java
License : Apache License 2.0
Project Creator : yuanmabiji

@Test
public void testConcurrentKafkaListenerContainerFactoryWithCustomMessageConverters() {
    this.contextRunner.withUserConfiguration(MessageConverterConfiguration.clreplaced).run((context) -> {
        ConcurrentKafkaListenerContainerFactory<?, ?> kafkaListenerContainerFactory = context.getBean(ConcurrentKafkaListenerContainerFactory.clreplaced);
        DirectFieldAccessor dfa = new DirectFieldAccessor(kafkaListenerContainerFactory);
        replacedertThat(dfa.getPropertyValue("messageConverter")).isSameAs(context.getBean("myMessageConverter"));
    });
}

19 View Source File : KafkaAutoConfigurationTests.java
License : Apache License 2.0
Project Creator : yuanmabiji

@Test
public void testConcurrentKafkaListenerContainerFactoryWithKafkaTemplate() {
    this.contextRunner.run((context) -> {
        ConcurrentKafkaListenerContainerFactory<?, ?> kafkaListenerContainerFactory = context.getBean(ConcurrentKafkaListenerContainerFactory.clreplaced);
        DirectFieldAccessor dfa = new DirectFieldAccessor(kafkaListenerContainerFactory);
        replacedertThat(dfa.getPropertyValue("replyTemplate")).isSameAs(context.getBean(KafkaTemplate.clreplaced));
    });
}

19 View Source File : KafkaConsumerConfig.java
License : MIT License
Project Creator : wuyouzhuguli

@Bean
public ConcurrentKafkaListenerContainerFactory<String, Message> kafkaListenerContainerFactory() {
    ConcurrentKafkaListenerContainerFactory<String, Message> factory = new ConcurrentKafkaListenerContainerFactory<>();
    factory.setConsumerFactory(consumerFactory());
    // factory.setRecordFilterStrategy(
    // r -> r.value().contains("replaced")
    // );
    return factory;
}

19 View Source File : KafkaConsumerConfig.java
License : GNU General Public License v3.0
Project Creator : wlhbdp

@Bean
public KafkaListenerContainerFactory<ConcurrentMessageListenerContainer<String, String>> kafkaListenerContainerFactory() {
    ConcurrentKafkaListenerContainerFactory<String, String> factory = new ConcurrentKafkaListenerContainerFactory();
    factory.setConsumerFactory(consumerFactory());
    return factory;
}

19 View Source File : KafkaConsumerConfig.java
License : Apache License 2.0
Project Creator : ververica

@Bean
public KafkaListenerContainerFactory<ConcurrentMessageListenerContainer<String, String>> kafkaListenerContainerFactory(ConsumerFactory<String, String> consumerFactory) {
    ConcurrentKafkaListenerContainerFactory<String, String> factory = new ConcurrentKafkaListenerContainerFactory<>();
    factory.setConsumerFactory(consumerFactory);
    return factory;
}

19 View Source File : KafkaConsumerConfig.java
License : Apache License 2.0
Project Creator : teixeira-fernando

@Bean
public ConcurrentKafkaListenerContainerFactory<String, Order> orderKafkaListenerContainerFactory() {
    ConcurrentKafkaListenerContainerFactory<String, Order> factory = new ConcurrentKafkaListenerContainerFactory<>();
    factory.setConsumerFactory(orderConsumerFactory());
    return factory;
}

19 View Source File : OrderConfig.java
License : MIT License
Project Creator : striderarun

@Bean
public ConcurrentKafkaListenerContainerFactory<Integer, String> kafkaListenerContainerFactory() {
    ConcurrentKafkaListenerContainerFactory<Integer, String> factory = new ConcurrentKafkaListenerContainerFactory<>();
    factory.setConsumerFactory(consumerFactory);
    return factory;
}

19 View Source File : TestConfiguration.java
License : Apache License 2.0
Project Creator : opentracing-contrib

@Bean
public ConcurrentKafkaListenerContainerFactory<Integer, String> kafkaListenerContainerFactory() {
    ConcurrentKafkaListenerContainerFactory<Integer, String> factory = new ConcurrentKafkaListenerContainerFactory<>();
    factory.setConsumerFactory(consumerFactory());
    return factory;
}

19 View Source File : ReceiverConfig.java
License : MIT License
Project Creator : mincloud1501

@Bean
public KafkaListenerContainerFactory<ConcurrentMessageListenerContainer<String, User>> kafkaListenerContainerFactory() {
    ConcurrentKafkaListenerContainerFactory<String, User> factory = new ConcurrentKafkaListenerContainerFactory<>();
    factory.setConsumerFactory(consumerFactory());
    // enable batch listening
    // factory.setBatchListener(true);
    return factory;
}

19 View Source File : KafkaConsumerConfig.java
License : MIT License
Project Creator : medmes

@Bean
public KafkaListenerContainerFactory<ConcurrentMessageListenerContainer<String, String>> kafkaListenerContainerFactory() {
    ConcurrentKafkaListenerContainerFactory<String, String> factory = new ConcurrentKafkaListenerContainerFactory<>();
    factory.setConsumerFactory(consumerFactory());
    return factory;
}

19 View Source File : SpringKafkaConsumptionConfig.java
License : Apache License 2.0
Project Creator : MAIF

@Bean
public ConcurrentKafkaListenerContainerFactory<String, EventEnvelope<BankEvent, Tuple0, Tuple0>> kafkaListenerContainerFactory(ConsumerFactory<String, EventEnvelope<BankEvent, Tuple0, Tuple0>> consumerFactory) {
    ConcurrentKafkaListenerContainerFactory<String, EventEnvelope<BankEvent, Tuple0, Tuple0>> factory = new ConcurrentKafkaListenerContainerFactory<>();
    factory.setConsumerFactory(consumerFactory);
    return factory;
}

19 View Source File : MessageConsumerConfig.java
License : MIT License
Project Creator : kimyuuum

@Bean
public KafkaListenerContainerFactory<ConcurrentMessageListenerContainer<String, String>> successKafkaListenerContainerFactory() {
    ConcurrentKafkaListenerContainerFactory<String, String> factory = new ConcurrentKafkaListenerContainerFactory<>();
    factory.setConsumerFactory(successConsumerFactory());
    return factory;
}

19 View Source File : MessageConsumerConfig.java
License : MIT License
Project Creator : kimyuuum

@Bean
public KafkaListenerContainerFactory<ConcurrentMessageListenerContainer<String, ExistDto.Response>> kafkaListenerContainerFactory() {
    ConcurrentKafkaListenerContainerFactory<String, ExistDto.Response> factory = new ConcurrentKafkaListenerContainerFactory<>();
    factory.setConsumerFactory(existConsumerFactory());
    return factory;
}

19 View Source File : KafkaConsumerConfig.java
License : MIT License
Project Creator : kimyuuum

@Bean
public KafkaListenerContainerFactory<ConcurrentMessageListenerContainer<String, WatchInfoDto.Request>> disconnectKafkaListenerContainerFactory() {
    ConcurrentKafkaListenerContainerFactory<String, WatchInfoDto.Request> factory = new ConcurrentKafkaListenerContainerFactory<>();
    factory.setConsumerFactory(disconnectConsumerFactory());
    return factory;
}

19 View Source File : KafkaConsumerConfig.java
License : MIT License
Project Creator : kimyuuum

@Bean
public KafkaListenerContainerFactory<ConcurrentMessageListenerContainer<String, WatchInfoDto.Request>> forceKafkaListenerContainerFactory() {
    ConcurrentKafkaListenerContainerFactory<String, WatchInfoDto.Request> factory = new ConcurrentKafkaListenerContainerFactory<>();
    factory.setConsumerFactory(forceConsumerFactory());
    return factory;
}

19 View Source File : KafkaConsumerConfig.java
License : MIT License
Project Creator : kimyuuum

@Bean
public KafkaListenerContainerFactory<ConcurrentMessageListenerContainer<String, WatchInfoDto.Request>> newKafkaListenerContainerFactory() {
    ConcurrentKafkaListenerContainerFactory<String, WatchInfoDto.Request> factory = new ConcurrentKafkaListenerContainerFactory<>();
    factory.setConsumerFactory(consumerFactory());
    return factory;
}

19 View Source File : KafkaConsumerConfig.java
License : Apache License 2.0
Project Creator : ebi-wp

@Bean
public ConcurrentKafkaListenerContainerFactory<String, String> rawKafkaListenerContainerFactory() {
    ConcurrentKafkaListenerContainerFactory<String, String> factory = new ConcurrentKafkaListenerContainerFactory<>();
    factory.setConsumerFactory(consumerFactory("groupId"));
    return factory;
}

19 View Source File : KafkaConfig.java
License : Mozilla Public License 2.0
Project Creator : diging

@Bean
public ConcurrentKafkaListenerContainerFactory kafkaListenerContainerFactory() {
    ConcurrentKafkaListenerContainerFactory factory = new ConcurrentKafkaListenerContainerFactory<>();
    factory.setConsumerFactory(consumerFactory());
    return factory;
}

19 View Source File : KafkaConfig.java
License : MIT License
Project Creator : dailycodebuffer

@Bean
public ConcurrentKafkaListenerContainerFactory concurrentKafkaListenerContainerFactory() {
    ConcurrentKafkaListenerContainerFactory<String, String> factory = new ConcurrentKafkaListenerContainerFactory<>();
    factory.setConsumerFactory(consumerFactory());
    return factory;
}

19 View Source File : ReceiverConfig.java
License : MIT License
Project Creator : code-not-found

@Bean
public ConcurrentKafkaListenerContainerFactory<String, String> kafkaListenerContainerFactory() {
    ConcurrentKafkaListenerContainerFactory<String, String> factory = new ConcurrentKafkaListenerContainerFactory<>();
    factory.setConsumerFactory(consumerFactory());
    factory.setMessageConverter(new StringJsonMessageConverter());
    return factory;
}

19 View Source File : ReceiverConfig.java
License : MIT License
Project Creator : code-not-found

@Bean
public ConcurrentKafkaListenerContainerFactory<String, Car> kafkaListenerContainerFactory() {
    ConcurrentKafkaListenerContainerFactory<String, Car> factory = new ConcurrentKafkaListenerContainerFactory<>();
    factory.setConsumerFactory(consumerFactory());
    return factory;
}

19 View Source File : ReceiverConfig.java
License : MIT License
Project Creator : code-not-found

@Bean
public ConcurrentKafkaListenerContainerFactory<String, String> kafkaListenerContainerFactory() {
    ConcurrentKafkaListenerContainerFactory<String, String> factory = new ConcurrentKafkaListenerContainerFactory<>();
    factory.setConsumerFactory(consumerFactory());
    // enable batch listening
    factory.setBatchListener(true);
    return factory;
}

19 View Source File : ReceiverConfig.java
License : MIT License
Project Creator : code-not-found

@Bean
public ConcurrentKafkaListenerContainerFactory<String, User> kafkaListenerContainerFactory() {
    ConcurrentKafkaListenerContainerFactory<String, User> factory = new ConcurrentKafkaListenerContainerFactory<>();
    factory.setConsumerFactory(consumerFactory());
    return factory;
}

19 View Source File : KafkaConsumerConfig.java
License : MIT License
Project Creator : batux

@Bean
public ConcurrentKafkaListenerContainerFactory<String, MailContext> mailContextListenerContainerFactory() {
    ConcurrentKafkaListenerContainerFactory<String, MailContext> factory = new ConcurrentKafkaListenerContainerFactory<>();
    factory.setConsumerFactory(mailContextConsumerFactory());
    return factory;
}

18 View Source File : KafkaAutoConfigurationTests.java
License : Apache License 2.0
Project Creator : yuanmabiji

@Test
public void testConcurrentKafkaListenerContainerFactoryWithCustomTransactionManager() {
    this.contextRunner.withUserConfiguration(TransactionManagerConfiguration.clreplaced).withPropertyValues("spring.kafka.producer.transaction-id-prefix=test").run((context) -> {
        ConcurrentKafkaListenerContainerFactory<?, ?> factory = context.getBean(ConcurrentKafkaListenerContainerFactory.clreplaced);
        replacedertThat(factory.getContainerProperties().getTransactionManager()).isSameAs(context.getBean("chainedTransactionManager"));
    });
}

18 View Source File : KafkaAutoConfigurationTests.java
License : Apache License 2.0
Project Creator : yuanmabiji

@Test
public void testConcurrentKafkaListenerContainerFactoryWithCustomErrorHandler() {
    this.contextRunner.withUserConfiguration(ErrorHandlerConfiguration.clreplaced).run((context) -> {
        ConcurrentKafkaListenerContainerFactory<?, ?> factory = context.getBean(ConcurrentKafkaListenerContainerFactory.clreplaced);
        replacedertThat(KafkaTestUtils.getPropertyValue(factory, "errorHandler")).isSameAs(context.getBean("errorHandler"));
    });
}

18 View Source File : KafkaAutoConfigurationTests.java
License : Apache License 2.0
Project Creator : yuanmabiji

@Test
public void testConcurrentKafkaListenerContainerFactoryWithDefaultTransactionManager() {
    this.contextRunner.withPropertyValues("spring.kafka.producer.transaction-id-prefix=test").run((context) -> {
        replacedertThat(context).hreplacedingleBean(KafkaAwareTransactionManager.clreplaced);
        ConcurrentKafkaListenerContainerFactory<?, ?> factory = context.getBean(ConcurrentKafkaListenerContainerFactory.clreplaced);
        replacedertThat(factory.getContainerProperties().getTransactionManager()).isSameAs(context.getBean(KafkaAwareTransactionManager.clreplaced));
    });
}

18 View Source File : KafkaAnnotationDrivenConfiguration.java
License : Apache License 2.0
Project Creator : yuanmabiji

@Bean
@ConditionalOnMissingBean(name = "kafkaListenerContainerFactory")
public ConcurrentKafkaListenerContainerFactory<?, ?> kafkaListenerContainerFactory(ConcurrentKafkaListenerContainerFactoryConfigurer configurer, ConsumerFactory<Object, Object> kafkaConsumerFactory) {
    ConcurrentKafkaListenerContainerFactory<Object, Object> factory = new ConcurrentKafkaListenerContainerFactory<>();
    configurer.configure(factory, kafkaConsumerFactory);
    return factory;
}

18 View Source File : KafkaConfig.java
License : Apache License 2.0
Project Creator : telstra

@Bean
public ConcurrentKafkaListenerContainerFactory<?, ?> kafkaListenerContainerFactory(ConcurrentKafkaListenerContainerFactoryConfigurer configurer, ConsumerFactory<Object, Object> kafkaConsumerFactory, @Autowired KafkaRecordFilter kafkaRecordFilter) {
    ConcurrentKafkaListenerContainerFactory<Object, Object> factory = new ConcurrentKafkaListenerContainerFactory<>();
    configurer.configure(factory, kafkaConsumerFactory);
    // didn't find annotation
    factory.setRecordFilterStrategy(kafkaRecordFilter);
    return factory;
}

18 View Source File : MessageConsumerConfig.java
License : Apache License 2.0
Project Creator : telstra

/**
 * Kafka listener container factory bean. Returned instance builds
 * {@link org.springframework.kafka.listener.ConcurrentMessageListenerContainer}
 * using the {@link org.apache.kafka.clients.consumer.Consumer}.
 *
 * @return kafka listener container factory
 */
@Bean
public ConcurrentKafkaListenerContainerFactory<String, Message> kafkaListenerContainerFactory(ConsumerFactory<String, Message> consumerFactory) {
    ConcurrentKafkaListenerContainerFactory<String, Message> factory = new ConcurrentKafkaListenerContainerFactory<>();
    factory.setConsumerFactory(consumerFactory);
    factory.getContainerProperties().setPollTimeout(POLL_TIMEOUT);
    factory.setConcurrency(kafkaListeners);
    return factory;
}

18 View Source File : Application.java
License : Apache License 2.0
Project Creator : spring-cloud-samples

@Bean
public ConcurrentKafkaListenerContainerFactory<?, ?> kafkaListenerContainerFactory(ConcurrentKafkaListenerContainerFactoryConfigurer configurer, ConsumerFactory<Object, Object> kafkaConsumerFactory, KafkaTemplate<Object, Object> template) {
    ConcurrentKafkaListenerContainerFactory<Object, Object> factory = new ConcurrentKafkaListenerContainerFactory<>();
    configurer.configure(factory, kafkaConsumerFactory);
    factory.setErrorHandler(new SeekToCurrentErrorHandler(new DeadLetterPublishingRecoverer(template), // dead-letter after 3 tries
    new FixedBackOff(5000L, 3)));
    return factory;
}

18 View Source File : KafkaConsumerConfig.java
License : Apache License 2.0
Project Creator : scholzj

@Bean
public ConcurrentKafkaListenerContainerFactory<String, String> kafkaListenerContainerFactory() {
    ConcurrentKafkaListenerContainerFactory<String, String> factory = new ConcurrentKafkaListenerContainerFactory<>();
    factory.setConsumerFactory(consumerFactory());
    factory.setAckDiscarded(true);
    factory.getContainerProperties().setAckMode(ContainerProperties.AckMode.COUNT_TIME);
    return factory;
}

18 View Source File : AbstractKafkaConsumerConfig.java
License : Apache License 2.0
Project Creator : OSGP

private ConcurrentKafkaListenerContainerFactory<K, V> initKafkaListenerContainerFactory(final int concurrency, final int pollTimeout) {
    final ConcurrentKafkaListenerContainerFactory<K, V> factory = new ConcurrentKafkaListenerContainerFactory<>();
    factory.setConsumerFactory(this.consumerFactory);
    factory.setConcurrency(concurrency);
    factory.getContainerProperties().setPollTimeout(pollTimeout);
    return factory;
}

18 View Source File : KafkaConfig.java
License : Apache License 2.0
Project Creator : kaituozhesh

/**
 * 消息过滤
 *
 * @return
 */
@Bean
public KafkaListenerContainerFactory<?> filterContainerFactory(ConsumerFactory consumerFactory) {
    ConcurrentKafkaListenerContainerFactory factory = new ConcurrentKafkaListenerContainerFactory();
    factory.setConsumerFactory(consumerFactory);
    // 配合RecordFilterStrategy使用,被过滤的信息将被丢弃
    factory.setAckDiscarded(true);
    factory.setRecordFilterStrategy(consumerRecord -> {
        String msg = (String) consumerRecord.value();
        if (msg.contains("abc")) {
            return false;
        }
        System.out.println("filterContainerFactory filter : " + msg);
        // 返回true将会被丢弃
        return true;
    });
    return factory;
}

18 View Source File : ErrorConfiguration.java
License : Apache License 2.0
Project Creator : faster-framework

/**
 * @param concurrentKafkaListenerContainerFactory concurrentKafkaListenerContainerFactory
 * @return 普通处理器
 */
@Bean
@ConditionalOnMissingBean
public GenericErrorHandler kafkaBatchErrorHandler(ConcurrentKafkaListenerContainerFactory concurrentKafkaListenerContainerFactory) {
    // 此处之所以要获取bean而非获取配置文件进行判断,因为spring-kafka允许注册自定义factory并且设置batchListener为true,此时配置文件参数可为空。
    if (concurrentKafkaListenerContainerFactory.isBatchListener() != null && concurrentKafkaListenerContainerFactory.isBatchListener()) {
        BatchErrorHandler batchErrorHandler = new KafkaBatchErrorHandler();
        concurrentKafkaListenerContainerFactory.setBatchErrorHandler(batchErrorHandler);
        return batchErrorHandler;
    } else {
        ErrorHandler errorHandler = new KafkaErrorHandler();
        concurrentKafkaListenerContainerFactory.setErrorHandler(errorHandler);
        return errorHandler;
    }
}

17 View Source File : UserRequestConsumer.java
License : GNU General Public License v3.0
Project Creator : xsreality

@Bean
public ConcurrentKafkaListenerContainerFactory<String, UserRequest> userRequestsKafkaListenerContainerFactory() {
    ConcurrentKafkaListenerContainerFactory<String, UserRequest> factory = new ConcurrentKafkaListenerContainerFactory<>();
    factory.setConsumerFactory(userRequestsConsumerFactory());
    factory.setMissingTopicsFatal(false);
    return factory;
}

17 View Source File : KafkaConfig.java
License : MIT License
Project Creator : xkcoding

@Bean("ackContainerFactory")
public ConcurrentKafkaListenerContainerFactory<String, String> ackContainerFactory() {
    ConcurrentKafkaListenerContainerFactory<String, String> factory = new ConcurrentKafkaListenerContainerFactory<>();
    factory.setConsumerFactory(consumerFactory());
    factory.getContainerProperties().setAckMode(ContainerProperties.AckMode.MANUAL_IMMEDIATE);
    factory.setConcurrency(KafkaConsts.DEFAULT_PARreplacedION_NUM);
    return factory;
}

17 View Source File : KafkaConfig.java
License : MIT License
Project Creator : xkcoding

@Bean
public ConcurrentKafkaListenerContainerFactory<String, String> kafkaListenerContainerFactory() {
    ConcurrentKafkaListenerContainerFactory<String, String> factory = new ConcurrentKafkaListenerContainerFactory<>();
    factory.setConsumerFactory(consumerFactory());
    factory.setConcurrency(KafkaConsts.DEFAULT_PARreplacedION_NUM);
    factory.setBatchListener(true);
    factory.getContainerProperties().setPollTimeout(3000);
    return factory;
}

17 View Source File : JsonConfiguration.java
License : Apache License 2.0
Project Creator : SpringOnePlatform2016

@Bean
public ConcurrentKafkaListenerContainerFactory<String, Foo> kafkaListenerContainerFactory() {
    ConcurrentKafkaListenerContainerFactory<String, Foo> factory = new ConcurrentKafkaListenerContainerFactory<>();
    factory.setConsumerFactory(consumerFactory());
    return factory;
}

17 View Source File : CommonConfiguration.java
License : Apache License 2.0
Project Creator : SpringOnePlatform2016

@Bean
public ConcurrentKafkaListenerContainerFactory<String, String> kafkaListenerContainerFactory() {
    ConcurrentKafkaListenerContainerFactory<String, String> factory = new ConcurrentKafkaListenerContainerFactory<>();
    factory.setConsumerFactory(consumerFactory());
    return factory;
}

17 View Source File : AbstractKafkaConsumerConfig.java
License : Apache License 2.0
Project Creator : OSGP

public abstract clreplaced AbstractKafkaConsumerConfig<K, V> extends KafkaConfig {

    private static final Logger LOGGER = LoggerFactory.getLogger(AbstractKafkaConsumerConfig.clreplaced);

    private ConsumerFactory<K, V> consumerFactory;

    private ConcurrentKafkaListenerContainerFactory<K, V> kafkaListenerContainerFactory;

    public AbstractKafkaConsumerConfig(final Environment environment, final String propertiesPrefix, final String topic, final int concurrency, final int pollTimeout) {
        super(environment);
        LOGGER.debug("=================================================================================");
        LOGGER.info("Initializing Kafka Consumer for Topic {}", topic);
        LOGGER.debug("Common properties prefix: {}", propertiesPrefix);
        LOGGER.debug("Consumer properties prefix: {}", getConsumerPropertiesPrefix(propertiesPrefix));
        LOGGER.debug("=================================================================================");
        this.initKafkaConsumer(propertiesPrefix, concurrency, pollTimeout);
    }

    public abstract ConsumerFactory<K, V> consumerFactory();

    public abstract ConcurrentKafkaListenerContainerFactory<K, V> kafkaListenerContainerFactory();

    protected ConsumerFactory<K, V> getConsumerFactory() {
        return this.consumerFactory;
    }

    protected ConcurrentKafkaListenerContainerFactory<K, V> getKafkaListenerContainerFactory() {
        return this.kafkaListenerContainerFactory;
    }

    private static String getConsumerPropertiesPrefix(final String propertiesPrefix) {
        return propertiesPrefix + ".consumer";
    }

    private void initKafkaConsumer(final String propertiesPrefix, final int concurrency, final int pollTimeout) {
        final Map<String, Object> consumerConfigs = this.consumerConfigs(propertiesPrefix);
        this.consumerFactory = new DefaultKafkaConsumerFactory<>(consumerConfigs);
        this.kafkaListenerContainerFactory = this.initKafkaListenerContainerFactory(concurrency, pollTimeout);
    }

    private ConcurrentKafkaListenerContainerFactory<K, V> initKafkaListenerContainerFactory(final int concurrency, final int pollTimeout) {
        final ConcurrentKafkaListenerContainerFactory<K, V> factory = new ConcurrentKafkaListenerContainerFactory<>();
        factory.setConsumerFactory(this.consumerFactory);
        factory.setConcurrency(concurrency);
        factory.getContainerProperties().setPollTimeout(pollTimeout);
        return factory;
    }

    private Map<String, Object> consumerConfigs(final String propertiesPrefix) {
        final Map<String, Object> properties = this.createCommonProperties(propertiesPrefix);
        KafkaProperties.consumerProperties().forEach((k, v) -> this.addIfExist(properties, k, getConsumerPropertiesPrefix(propertiesPrefix), v));
        return properties;
    }
}

17 View Source File : KafkaListenerContainerFactoryConfiguration.java
License : Mozilla Public License 2.0
Project Creator : opfab

@Bean
public KafkaListenerContainerFactory<ConcurrentMessageListenerContainer<String, CardCommand>> kafkaListenerContainerFactory() {
    KafkaProperties.Listener listener = kafkaProperties.getListener();
    Integer concurrency = getConcurrency(listener);
    Long pollTimeOut = getPollTimeout(listener);
    log.info("Concurrency: " + concurrency);
    log.info("PollTimeout: " + pollTimeOut);
    ConcurrentKafkaListenerContainerFactory<String, CardCommand> factory = new ConcurrentKafkaListenerContainerFactory<>();
    factory.setConsumerFactory(consumerFactory);
    factory.setConcurrency(concurrency);
    factory.getContainerProperties().setPollTimeout(pollTimeOut);
    return factory;
}

17 View Source File : KafkaConfig.java
License : Apache License 2.0
Project Creator : kaituozhesh

/**
 * ConcurrentKafkaListenerContainerFactory为创建Kafka监听器的工厂类
 *
 * @param consumerFactory
 * @return
 */
@Bean
public KafkaListenerContainerFactory<?> batchFactory(ConsumerFactory consumerFactory) {
    ConcurrentKafkaListenerContainerFactory<Integer, String> factory = new ConcurrentKafkaListenerContainerFactory<>();
    factory.setConsumerFactory(consumerFactory);
    factory.setConcurrency(10);
    factory.getContainerProperties().setPollTimeout(1500);
    factory.setBatchListener(true);
    return factory;
}

17 View Source File : KafkaConfiguration.java
License : GNU General Public License v3.0
Project Creator : HaydiKodlayalim

@Bean
public ConcurrentKafkaListenerContainerFactory<String, KMessage> kafkaListenerContainerFactory() {
    ConcurrentKafkaListenerContainerFactory<String, KMessage> factory = new ConcurrentKafkaListenerContainerFactory<>();
    factory.setConsumerFactory(consumerFactory());
    return factory;
}

17 View Source File : DemoApplication.java
License : GNU General Public License v3.0
Project Creator : hantsy

@Bean
public ConcurrentKafkaListenerContainerFactory<?, ?> kafkaListenerContainerFactory(ConcurrentKafkaListenerContainerFactoryConfigurer configurer, ConsumerFactory<Object, Object> kafkaConsumerFactory, ChainedKafkaTransactionManager<Object, Object> chainedTM) {
    ConcurrentKafkaListenerContainerFactory<Object, Object> factory = new ConcurrentKafkaListenerContainerFactory<>();
    configurer.configure(factory, kafkaConsumerFactory);
    factory.getContainerProperties().setTransactionManager(chainedTM);
    return factory;
}

17 View Source File : ErrorConfiguration.java
License : Apache License 2.0
Project Creator : faster-framework

/**
 * @param kafkaTemplate                           操作类
 * @param concurrentKafkaListenerContainerFactory concurrentKafkaListenerContainerFactory
 * @return 死信批量处理器
 */
@Bean
@ConditionalOnProperty(prefix = "app.kafka.error", name = "dead-letter", havingValue = "true")
@ConditionalOnMissingBean
public GenericErrorHandler kafkaDeadLetterBatchErrorHandler(KafkaTemplate<Object, Object> kafkaTemplate, ConcurrentKafkaListenerContainerFactory concurrentKafkaListenerContainerFactory) {
    // 此处之所以要获取bean而非获取配置文件进行判断,因为spring-kafka允许注册自定义factory并且设置batchListener为true,此时配置文件参数可为空。
    if (concurrentKafkaListenerContainerFactory.isBatchListener() != null && concurrentKafkaListenerContainerFactory.isBatchListener()) {
        BatchErrorHandler batchErrorHandler = new KafkaDeadLetterBatchErrorHandler(kafkaTemplate);
        concurrentKafkaListenerContainerFactory.setBatchErrorHandler(batchErrorHandler);
        return batchErrorHandler;
    } else {
        ErrorHandler errorHandler = new KafkaDeadLetterErrorHandler(kafkaTemplate);
        concurrentKafkaListenerContainerFactory.setErrorHandler(errorHandler);
        return errorHandler;
    }
}

17 View Source File : EventasiaKafkaConfig.java
License : Apache License 2.0
Project Creator : Eventasia

@Bean
ConcurrentKafkaListenerContainerFactory<Integer, String> kafkaListenerContainerFactory() {
    ConcurrentKafkaListenerContainerFactory<Integer, String> factory = new ConcurrentKafkaListenerContainerFactory<>();
    factory.setConsumerFactory(consumerFactory());
    return factory;
}

16 View Source File : StatsAlertConsumerConfig.java
License : GNU General Public License v3.0
Project Creator : xsreality

@Bean
public ConcurrentKafkaListenerContainerFactory<String, StatewiseDelta> statewiseAlertsKafkaListenerContainerFactory() {
    ConcurrentKafkaListenerContainerFactory<String, StatewiseDelta> factory = new ConcurrentKafkaListenerContainerFactory<>();
    factory.setConsumerFactory(statewiseAlertsConsumerFactory());
    factory.setMissingTopicsFatal(false);
    factory.setBatchListener(true);
    return factory;
}

16 View Source File : DistrictAlertConsumer.java
License : GNU General Public License v3.0
Project Creator : xsreality

@Bean
public ConcurrentKafkaListenerContainerFactory<String, StatewiseDelta> districtAlertsKafkaListenerContainerFactory() {
    ConcurrentKafkaListenerContainerFactory<String, StatewiseDelta> factory = new ConcurrentKafkaListenerContainerFactory<>();
    factory.setConsumerFactory(districtAlertsConsumerFactory());
    factory.setMissingTopicsFatal(false);
    factory.setBatchListener(true);
    return factory;
}

See More Examples