向节点1001发送提取请求(sessionId=INVALID,epoch=INITIAL)时出错:org.apache.kafka.common.errors.DisconnectException

amrnrhlw  于 2023-06-21  发布在  Apache
关注(0)|答案(3)|浏览(248)

我正在使用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:2io.confluent.kafka-avro-serializer:3.2.1

gj3fmq9x

gj3fmq9x1#

正如@Ahmad Abdelghany评论所说,设置org.apache.kafka日志到调试显示:

DEBUG org.apache.kafka.clients.NetworkClient - Disconnecting from node 1 due to request timeout.
DEBUG org.apache.kafka.clients.consumer.internals.ConsumerNetworkClient - Cancelled request with header RequestHeader(apiKey=FETCH, apiVersion=11, clientId=consumer-1, correlationId=183) due to node 1 being disconnected
DEBUG org.apache.kafka.clients.NetworkClient - Give up sending metadata request since no node is available
INFO org.apache.kafka.clients.FetchSessionHandler - Error sending fetch request (sessionId=INVALID, epoch=INITIAL) to node 1: {}.
org.apache.kafka.common.errors.DisconnectException: null
DEBUG org.apache.kafka.clients.NetworkClient - Give up sending metadata request since no node is available

重要的是:
由于请求超时
您可以增加request.timeout.ms(默认值为30000)

props.put(ConsumerConfig.REQUEST_TIMEOUT_MS_CONFIG, "60000");
  • 注意:您的情况应该有所不同,因为您的超时设置为10分钟。显示调试日志应该会有帮助。*
rvpgvaaj

rvpgvaaj2#

我也有类似的问题。在我的例子中,它发生了,因为Kafka在connections.max.idle.ms之后关闭了消费者连接(默认为10分钟)。
我在消费者日志中看到了下一条消息:

11-01-2022 08:35:09.498 DEBUG o.a.k.c.n.Selector.pollSelectionKeys - [Consumer clientId=abc, groupId=abc] Connection with localhost/127.0.0.1 disconnected
java.io.EOFException: null
at org.apache.kafka.common.network.NetworkReceive.readFrom(NetworkReceive.java:97)
at org.apache.kafka.common.network.KafkaChannel.receive(KafkaChannel.java:447)
at org.apache.kafka.common.network.KafkaChannel.read(KafkaChannel.java:397)
at org.apache.kafka.common.network.Selector.attemptRead(Selector.java:674)
at org.apache.kafka.common.network.Selector.pollSelectionKeys(Selector.java:576)
at org.apache.kafka.common.network.Selector.poll(Selector.java:481)
at org.apache.kafka.clients.NetworkClient.poll(NetworkClient.java:563)
at org.apache.kafka.clients.consumer.internals.ConsumerNetworkClient.poll(ConsumerNetworkClient.java:265)
at org.apache.kafka.clients.consumer.internals.ConsumerNetworkClient.poll(ConsumerNetworkClient.java:236)
at org.apache.kafka.clients.consumer.KafkaConsumer.pollForFetches(KafkaConsumer.java:1292)
at org.apache.kafka.clients.consumer.KafkaConsumer.poll(KafkaConsumer.java:1233)
at org.apache.kafka.clients.consumer.KafkaConsumer.poll(KafkaConsumer.java:1206)
at sun.reflect.GeneratedMethodAccessor255.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:344)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:208)
at com.sun.proxy.$Proxy426.poll(Unknown Source)
at org.springframework.kafka.listener.KafkaMessageListenerContainer$ListenerConsumer.doPoll(KafkaMessageListenerContainer.java:1410)
at org.springframework.kafka.listener.KafkaMessageListenerContainer$ListenerConsumer.pollAndInvoke(KafkaMessageListenerContainer.java:1249)
at org.springframework.kafka.listener.KafkaMessageListenerContainer$ListenerConsumer.run(KafkaMessageListenerContainer.java:1161)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.lang.Thread.run(Thread.java:748)

因此,尝试在消费者配置中减少fetch.max.wait.ms,或在代理配置中增加connections.max.idle.ms

kgqe7b3p

kgqe7b3p3#

我们也遇到过类似的问题。我们删除了消费者组并重新创建了它,这有助于

相关问题