还真是停机导致的,我加多个@kafkalistener,spring容器不会关闭,就不会出现producer被强制关闭这个问题了;
但是,我实现CommandLineRunner接口,在run方法内部循环发送,理论上也要执行完发送消息逻辑才会停机吧?,除非CommandLineRunner有时间限制?能帮忙解答下吗??
代码如下:
@SpringBootApplication
@EnableKafka
public class KafkaExampleApplication implements CommandLineRunner {
public static void main(String[] args) {
SpringApplication.run(KafkaExampleApplication.class, args);
}
@Autowired
private KafkaProducerExample kafkaProducerExample;
@Autowired
private KafkaProducerUtil kafkaProducerUtil;
@Override
public void run(String... args) {
for (int i=0; i<50000; i++) { kafkaProducerExample.sendMsg(); } } }