Search in sources :

Example 1 with ConcurrentMessageListenerContainer

use of org.springframework.kafka.listener.ConcurrentMessageListenerContainer in project xm-ms-entity by xm-online.

the class ApplicationStartup method createSystemConsumer.

private void createSystemConsumer(String name, MessageListener<String, String> consumeEvent) {
    log.info("Creating kafka consumer for topic {}", name);
    ContainerProperties containerProps = new ContainerProperties(name);
    Map<String, Object> props = kafkaProperties.buildConsumerProperties();
    if (name.equals(applicationProperties.getKafkaSystemTopic())) {
        props.put(ConsumerConfig.GROUP_ID_CONFIG, UUID.randomUUID().toString());
    }
    ConsumerFactory<String, String> factory = new DefaultKafkaConsumerFactory<>(props);
    ConcurrentMessageListenerContainer<String, String> container = new ConcurrentMessageListenerContainer<>(factory, containerProps);
    container.setupMessageListener(consumeEvent);
    container.start();
    log.info("Successfully created kafka consumer for topic {}", name);
}
Also used : ContainerProperties(org.springframework.kafka.listener.config.ContainerProperties) ConcurrentMessageListenerContainer(org.springframework.kafka.listener.ConcurrentMessageListenerContainer) DefaultKafkaConsumerFactory(org.springframework.kafka.core.DefaultKafkaConsumerFactory)

Aggregations

DefaultKafkaConsumerFactory (org.springframework.kafka.core.DefaultKafkaConsumerFactory)1 ConcurrentMessageListenerContainer (org.springframework.kafka.listener.ConcurrentMessageListenerContainer)1 ContainerProperties (org.springframework.kafka.listener.config.ContainerProperties)1