• Spring-Kafka —— KafkaListener禁止自启动


    应用服务启动时,KafkaListener默认会自动启动进行消费,如果想不自动消费,可以设置AutoStartup属性值为false

        @Override
        @KafkaListener(id = ConsumerConst.LISTENER_ID_WARNING, topics = {"${kafka.app.topic.warning}"}, containerFactory = "ackContainerFactory", groupId = "warning")
        public void ackListener(ConsumerRecord record, Acknowledgment ack) {
            if (LOG.isInfoEnabled()) {
                LOG.info("###################预警ackListener接收到消息###################");
            }
         // todo 消费业务处理        
        }
        @Bean("ackContainerFactory")
        public ConcurrentKafkaListenerContainerFactory ackContainerFactory(ConsumerFactory consumerFactory) {
            ConcurrentKafkaListenerContainerFactory factory = new ConcurrentKafkaListenerContainerFactory();
            factory.setConsumerFactory(consumerFactory);
            //容器线程数:小于或等于Topic的分区数
            factory.setConcurrency(3);
            //设置提交偏移量的方式
            factory.getContainerProperties().setAckMode(AbstractMessageListenerContainer.AckMode.MANUAL_IMMEDIATE);
            // 禁止自动启动
            factory.setAutoStartup(false);
            return factory;
        }

    完整消费代码vk

  • 相关阅读:
    LeetCode
    (六)6.5 Neurons Networks Implements of Sparse Autoencoder
    (六)6.4 Neurons Networks Autoencoders and Sparsity
    (六) 6.3 Neurons Networks Gradient Checking
    opencv::调整图像亮度与对比度
    opencv::两张图片的线性融合
    opencv::源码编译
    日志::spdlog
    std::is_same
    json::rapidjson工具
  • 原文地址:https://www.cnblogs.com/caoweixiong/p/11181443.html
Copyright © 2020-2023  润新知