博主你好! 我也遇到这样的问题,我想歘构建2个不同的producer该怎么解决?
最后是怎么解决的呢
ok,解决就好。
已经解决了,我是使用spring的kafka模版发送消息的,每次都新建了一个producer,没有使用到单例创建producer,导致kafka报了异常,阻止新的producer继续创建。kafka抛异常的源码:
private KafkaProducer(ProducerConfig config, Serializer<K> keySerializer, Serializer<V> valueSerializer) {
try {
log.trace("Starting the Kafka producer");
....
} catch (Throwable t) {
// call close methods if internal objects are already constructed this is to prevent resource leak. see KAFKA-2121
close(0, TimeUnit.MILLISECONDS, true);
// now propagate the exception
throw new KafkaException("Failed to construct kafka producer", t);
}