我的计算机中正在运行消费者。当我停止Kafka经纪人时,我的应用程序中收到
的警告"org.apache.kafka.clients.NetworkClient: [Consumer clientId=Data-client-0, groupId=Consumer_group] Connection to node 0 could not be established. Broker may not be available."
但是NonResponsiveConsumerEvent
在2-4分钟范围内触发。根据本文档https://github.com/spring-projects/spring-kafka/blob/master/src/reference/asciidoc/kafka.adoc#idle-containers
它说:“如果轮询未在pollInterval属性的3倍之内返回,则容器将发布NonResponsiveConsumerEvent。”我的轮询间隔为5分钟,并且我将noPollThreshold
设置为1L。它应该在5分钟后触发此事件,但我会在2-4分钟后收到此事件。
我尝试将max.poll.interval.ms
更改为30秒-为此,有时会在应用程序启动时触发事件,然后在2-4分钟后触发下一个事件。
我的consumerconfig
2019-10-15 13:12:54,403 INFO [main] org.apache.kafka.common.config.AbstractConfig: ConsumerConfig values:
auto.commit.interval.ms = 5000
auto.offset.reset = latest
bootstrap.servers = [localhost:9092]
check.crcs = true
client.id = Data-client-0
connections.max.idle.ms = 540000
default.api.timeout.ms = 60000
enable.auto.commit = false
exclude.internal.topics = true
fetch.max.bytes = 52428800
fetch.max.wait.ms = 500
fetch.min.bytes = 1
group.id = Consumer_group
heartbeat.interval.ms = 3000
interceptor.classes = []
internal.leave.group.on.close = true
isolation.level = read_uncommitted
key.deserializer = class org.apache.kafka.common.serialization.ByteArrayDeserializer
max.partition.fetch.bytes = 1048576
max.poll.interval.ms = 300000
max.poll.records = 500
metadata.max.age.ms = 300000
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]
receive.buffer.bytes = 65536
reconnect.backoff.max.ms = 1000
reconnect.backoff.ms = 50
request.timeout.ms = 30000
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
session.timeout.ms = 10000
ssl.cipher.suites = null
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 org.apache.kafka.common.serialization.ByteArrayDeserializer
2019-10-15 13:12:54,461 INFO [main] org.apache.kafka.common.utils.AppInfoParser$AppInfo: Kafka version : 2.0.1
2019-10-15 13:12:54,462 INFO [main] org.apache.kafka.common.utils.AppInfoParser$AppInfo: Kafka commitId : fa14705e51bd2ce5
2019-10-15 13:12:54,466 INFO [main] org.springframework.scheduling.concurrent.ExecutorConfigurationSupport: Initializing ExecutorService
2019-10-15 13:12:54,469 INFO [main] org.springframework.core.log.LogAccessor: KafkaMessageListenerContainer.ListenerConsumer [containerProperties=ContainerProperties [topics=[row], pollTimeout=5000, groupId=Consumer_group, consumerRebalanceListener=org.springframework.kafka.listener.AbstractMessageListenerContainer$1@41962299, syncCommits=true, ackMode=MANUAL_IMMEDIATE, ackCount=0, ackTime=0, messageListener=org.springframework.kafka.listener.adapter.RecordMessagingMessageListenerAdapter@3f910f36, consumerTaskExecutor=org.springframework.core.task.SimpleAsyncTaskExecutor@6421bc7e, shutdownTimeout=10000, ackOnError=false, idleEventInterval=not enabled, monitorInterval=1, noPollThreshold=1.0], listenerType=ACKNOWLEDGING_CONSUMER_AWARE, isConsumerAwareListener=true, isBatchListener=false, autoCommit=false, consumerGroupId=Consumer_group, clientIdSuffix=-0]
我的容器道具
factory.getContainerProperties().setAckMode(AckMode.MANUAL_IMMEDIATE);
factory.getContainerProperties().setNoPollThreshold(1L);
factory.getContainerProperties().setMonitorInterval(1);
factory.getContainerProperties().setLogContainerConfig(true);
我正在使用spring-kafka 2.3.0.RELEASE
spring-boot-starter-parent 2.1.9.RELEASE
spring-core 5.2.0.RELEASE
我的事件监听器
@EventListener
public void eventHandler(NonResponsiveConsumerEvent event) {
System.out.println("NonResponsiveConsumerEvent event triggered"+ event.getListenerId());
}
答案 0 :(得分:0)
令您感到惊讶的是,因为经纪人去世时,现代客户不再陷入投票中,这让我感到惊讶。轮询超时,不返回任何记录,因此[build_menu]
FT_00_LB=_Compile
FT_00_CM=python -m py_compile "%f"
EX_00_LB=_Execute
EX_00_CM=python "%f"
在每次轮询之前都会更新。
文档中有错字。它应该说
”如果轮询未在lastPoll
属性的3倍之内返回,则容器将发布NonResponsiveConsumerEvent
。请注意 pollTimeout 不是 pollInterval 。>
阈值为1,看来您将pollTimeout
设置为2分钟,这可能导致这些事件被发布。由于比赛条件。阈值应大于1,以避免出现这种竞争情况。
实际上,pollTimeout
的设置可能并不重要,只是将阈值设置为1意味着每次民意测验都有一场比赛。