## `session.timeout.ms`
Kafka 文档定义:
>The timeout used to detect consumer failures when using Kafka's group management facility. The consumer sends periodic heartbeats to indicate its liveness to the broker. If no heartbeats are received by the broker before the expiration of this session timeout, then the broker will remove this consumer from the group and initiate a rebalance. Note that the value must be in the allowable range as configured in the broker configuration by `group.min.session.timeout.ms` and `group.max.session.timeout.ms`.
首先,当 broker 认为有 consumer 崩溃(比如线程挂掉、网络异常等)时,broker 会把崩溃的 consumer 从 consumer group 中移除,并触发一次 rebalance。而 consumer 通过周期性地向 broker 发送心跳来表明自己还“活着”,如果 consumer 崩溃,则 broker 无法收到心跳。
问题是 broker 无法收到心跳并不一定是 consumer 崩溃导致的,暂时的网络拥塞、网络故障也可能导致 broker 无法收到心跳,这种故障可能几秒钟就自动恢复了,实际上,目前没有办法通过心跳区分 consumer 是不是真的挂掉了。
所以 Kafka 很粗暴的通过 `session.timeout.ms` 定义一个最大的“心跳空白时间”,即心跳正常表明 broker 和 consumer 之间存在正常会话(session),如果超过 `session.timeout.ms` 配置的时间 broker 没有收到心跳,则 broker 就认为 consumer 真的挂了。
注意,consumer 配置的会话超时时间受限于 broker 对应配置,即 `session.timeout.ms` 的值必须位于:
* `group.min.session.timeout.ms`
* `group.max.session.timeout.ms`
区间范围内。
## `max.poll.interval.ms`
[Notable changes in 0.10.1.0](https://kafka.apache.org/documentation/#upgrade_1010_notable):
>The new Java Consumer now supports heartbeating from a background thread. There is a new configuration max.poll.interval.ms which controls the maximum time between poll invocations before the consumer will proactively leave the group (5 minutes by default). The value of the configuration request.timeout.ms must always be larger than max.poll.interval.ms because this is the maximum time that a JoinGroup request can block on the server while the consumer is rebalancing, so we have changed its default value to just above 5 minutes. Finally, the default value of session.timeout.ms has been adjusted down to 10 seconds, and the default value of max.poll.records has been changed to 500.
https://stackoverflow.com/questions/39730126/difference-between-session-timeout-ms-and-max-poll-interval-ms-for-kafka-0-10-0
https://cwiki.apache.org/confluence/display/KAFKA/KIP-62%3A+Allow+consumer+to+send+heartbeats+from+a+background+thread
https://markmail.org/message/oeg63goh3ed3qdap
https://cwiki.apache.org/confluence/display/KAFKA/KIP-62%3A+Allow+consumer+to+send+heartbeats+from+a+background+thread
# Kafka 会不会丢消息?
The guarantee that Kafka offers is that a committed message will not be lost, as long as there is at least one in sync replica alive, at all times.
when creating internal topics
https://cwiki.apache.org/confluence/display/KAFKA/KIP-173%3A+Add+prefix+to+StreamsConfig+to+enable+setting+default+internal+topic+configs
# KIP-328: Ability to suppress updates for KTables
https://cwiki.apache.org/confluence/display/KAFKA/KIP-328%3A+Ability+to+suppress+updates+for+KTables