我正在使用spring Kafka并面临一些错误Error sending fetch request (sessionId=INVALID, epoch=INITIAL) to node 1001: org.apache.kafka.common.errors.DisconnectException.
我的消费者生产者代码
@EnableKafka
@Configuration
public class KafkaConfig {
@Value(value = "${spring.kafka.consumer.bootstrap-servers}")
private String bootstrapAddress;
@Value(value = "${spring.kafka.consumer.registry-server}")
private String registryAddress;
@Value(value = "${spring.kafka.consumer.group-id}")
private String groupId;
@Bean
public ConsumerFactory<String, GenericRecord> consumerFactory() {
final Map<String, Object> props = new HashMap<>();
props.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, bootstrapAddress);
props.put(AbstractKafkaAvroSerDeConfig.SCHEMA_REGISTRY_URL_CONFIG, registryAddress);
props.put(ConsumerConfig.GROUP_ID_CONFIG, groupId);
props.put(ConsumerConfig.FETCH_MAX_WAIT_MS_CONFIG, 600000);
props.put(ConsumerConfig.REQUEST_TIMEOUT_MS_CONFIG, 600000);
final AvroSerde avroSerde = new AvroSerde();
avroSerde.configure(props, false);
props.put(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, StringDeserializer.class);
props.put(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, avroSerde.deserializer().getClass());
return new DefaultKafkaConsumerFactory<>(props, new StringDeserializer(), avroSerde.deserializer());
}
@Bean
@ConditionalOnMissingBean(name = "kafkaListenerContainerFactory")
public ConcurrentKafkaListenerContainerFactory<String, GenericRecord> kafkaListenerContainerFactory() {
final ConcurrentKafkaListenerContainerFactory<String, GenericRecord> factory =
new ConcurrentKafkaListenerContainerFactory<>();
factory.setConsumerFactory(consumerFactory());
factory.setConcurrency(1);
return factory;
}
@Bean
KafkaTemplate<String, AlertEvent> kafkaTemplate() {
return new KafkaTemplate<>(producerFactory());
}
@Bean
public ProducerFactory<String, AlertEvent> producerFactory() {
Map<String, Object> config = new HashMap<>();
config.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, bootstrapAddress);
config.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, StringSerializer.class);
config.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, getAlertGsonEncoder().getClass());
return new DefaultKafkaProducerFactory(config);
}
private static GsonEncoder<AlertEvent> getAlertGsonEncoder() {
final GsonEncoder<AlertEvent> valueSerializer = new GsonEncoder<>();
valueSerializer.configure(Collections.singletonMap(GsonEncoder.INSERT_SCHEMA_CONFIG, false), false);
return valueSerializer;
}
}
我得到的错误,无法理解为什么,请帮助.配置如下所示。
auto.commit.interval.ms = 5000,
auto.offset.reset = latest,
check.crcs = true,
bootstrap.servers = [kafka:9092],
client.dns.lookup = default,
default.api.timeout.ms = 60000,
connections.max.idle.ms = 540000,
client.id = ,
exclude.internal.topics = true,
enable.auto.commit = true,
fetch.max.bytes = 52428800,
fetch.max.wait.ms = 600000,
fetch.min.bytes = 1,
group.id = iot-brazilian-alert-hb03,
interceptor.classes = [],
heartbeat.interval.ms = 3000,
internal.leave.group.on.close = true,
isolation.level = read_uncommitted,
key.deserializer = class org.apache.kafka.common.serialization.StringDeserializer,
max.partition.fetch.bytes = 1048576,
max.poll.interval.ms = 300000,
metadata.max.age.ms = 300000,
max.poll.records = 500,
metric.reporters = [],
metrics.num.samples = 2,
metrics.recording.level = INFO,
metrics.sample.window.ms = 30000,
partition.assignment.strategy = [class org.apache.kafka.clients.consumer.RangeAssignor],
reconnect.backoff.max.ms = 1000,
receive.buffer.bytes = 65536,
reconnect.backoff.ms = 50,
request.timeout.ms = 600000,
retry.backoff.ms = 100,
sasl.client.callback.handler.class = null,
sasl.jaas.config = null,
sasl.kerberos.kinit.cmd = /usr/bin/kinit,
sasl.kerberos.min.time.before.relogin = 60000,
sasl.kerberos.service.name = null,
sasl.kerberos.ticket.renew.jitter = 0.05,
sasl.kerberos.ticket.renew.window.factor = 0.8,
sasl.login.callback.handler.class = null,
sasl.login.class = null,
sasl.login.refresh.buffer.seconds = 300,
sasl.login.refresh.min.period.seconds = 60,
sasl.login.refresh.window.factor = 0.8,
sasl.login.refresh.window.jitter = 0.05,
sasl.mechanism = GSSAPI,
security.protocol = PLAINTEXT,
send.buffer.bytes = 131072,
ssl.cipher.suites = null,
session.timeout.ms = 10000,
ssl.enabled.protocols = [TLSv1.2, TLSv1.1, TLSv1],
ssl.endpoint.identification.algorithm = https,
ssl.key.password = null,
ssl.keymanager.algorithm = SunX509,
ssl.keystore.location = null,
ssl.keystore.password = null,
ssl.keystore.type = JKS,
ssl.protocol = TLS,
ssl.provider = null,
ssl.secure.random.implementation = null,
ssl.trustmanager.algorithm = PKIX,
ssl.truststore.location = null,
ssl.truststore.password = null,
ssl.truststore.type = JKS,
value.deserializer = class com.blupa.iot.kafka.encoder.AvroWrapper
我不知道我做错了什么。我正在使用org.apache.avro:1:8:2
和io.confluent.kafka-avro-serializer:3.2.1
3条答案
按热度按时间gj3fmq9x1#
正如@Ahmad Abdelghany评论所说,设置
org.apache.kafka
日志到调试显示:重要的是:
由于请求超时
您可以增加
request.timeout.ms
(默认值为30000)rvpgvaaj2#
我也有类似的问题。在我的例子中,它发生了,因为Kafka在
connections.max.idle.ms
之后关闭了消费者连接(默认为10分钟)。我在消费者日志中看到了下一条消息:
因此,尝试在消费者配置中减少
fetch.max.wait.ms
,或在代理配置中增加connections.max.idle.ms
。kgqe7b3p3#
我们也遇到过类似的问题。我们删除了消费者组并重新创建了它,这有助于