代码之家  ›  专栏  ›  技术社区  ›  Roman Kagan mianos

有没有读卡夫卡主题的春季时间表的例子?

  •  1
  • Roman Kagan mianos  · 技术社区  · 5 年前

    1 回复  |  直到 5 年前
        1
  •  6
  •   Ryuzaki L    5 年前

    您可以禁用 autoStartup 然后手动启动卡夫卡 containers 使用 KafkaListenerEndpointRegistry start stop @KafkaListener Lifecycle Management

    public class KafkaConsumer {
    
     @Autowired
     private KafkaListenerEndpointRegistry registry;
    
      @KafkaListener(id = "myContainer", topics = "myTopic", autoStartup = "false")
      public void listen(...) { ... }
    
      @Schedule(cron = "")
      public void scheduledMethod() {
    
       registry.start();
    
       registry.stop()
      }
    

    但在上述方法中,不能保证来自kafka的所有消息都会在该时间段内被消耗(这取决于负载和处理速度)

        2
  •  1
  •   Ambuj    5 年前

    然后我取消订阅主题并关闭消费者。计划程序下次运行时,将再次处理指定的最大轮询记录限制。

    fixedDelayString完成前一个任务后,调度器将在指定的时间限制后启动。

    @EnableScheduling
    public class MessageScheduler{
    
            @Scheduled(initialDelayString = "${fixedInitialDelay.in.milliseconds}", fixedDelayString = "${fixedDelay.in.milliseconds}")
            public void run(){
    
                /*write your kafka consumer here with manual commit*/
    
                /*once your batch is finished processing unsubcribe and close the consumer*/
                    kafkaConsumer.unsubscribe();
                    kafkaConsumer.close();
            }
    
    }