云简-mian
这个是个电话面,问的也比较基础,可能感觉我工作年限比较长,没有问一些基础的东西。
1. 工作的内容,目前手里熟悉的项目,详细说明一下。我说了一下分账相关
2. 详细问了一下分账的流程,问了一些简单的问题,碰到问题如何解决的
3. 如何控制请求并发的问题
4. kafka如何保证消息不重复处理
5. kafka 如何保证消息不丢失
6. kafka如何保证消息有序(和kafka消息的获取策略还有一定关系,主动拉取,保证一个消费者拉一个分区)
7. kafka如果消费者数量小于分区的数量会有什么影响
一个主题可以配置多个分区,一个分区可以有多个消费者组消费,每个消费者组只有一个消费者能消费某条消息
应该没啥影响,如果多的话会产生闲置的消费者,如果有多个消费者组,组和组直接没有什么影响
生产者默认的分区策略是:
- 如果在发消息的时候指定了分区,则消息投递到指定的分区
- 如果没有指定分区,但是消息的key不为空,则基于key的哈希值来选择一个分区
- 如果既没有指定分区,且消息的key也是空,则用轮询的方式选择一个分区
消费者分区分配策略
当消费者加入群组的时候,会根据分区分配策略决定哪些分区分配给哪些消费者。
Kafka有两种分配策略:Range和RoundRobin。
- Range(默认分配策略)
Topic的若干个连续的Partition分配给消费者。 - RoundRobin
Topic的所有Partition逐个分配给消费者。
Range 分配策略源码:
/** * The range assignor works on a per-topic basis. For each topic, we lay out the available partitions in numeric order * and the consumers in lexicographic order. We then divide the number of partitions by the total number of * consumers to determine the number of partitions to assign to each consumer. If it does not evenly * divide, then the first few consumers will have one extra partition. * * For example, suppose there are two consumers C0 and C1, two topics t0 and t1, and each topic has 3 partitions, * resulting in partitions t0p0, t0p1, t0p2, t1p0, t1p1, and t1p2. * * The assignment will be: * C0: [t0p0, t0p1, t1p0, t1p1] * C1: [t0p2, t1p2] */
这里是3个分区,两个消费则,除了以后是C0负责前面两个分区,C1 负责后面一个分区
roundrobin(轮询)
roundronbin分配策略的具体实现是org.apache.kafka.clients.consumer.RoundRobinAssignor
/** * The round robin assignor lays out all the available partitions and all the available consumers. It * then proceeds to do a round robin assignment from partition to consumer. If the subscriptions of all consumer * instances are identical, then the partitions will be uniformly distributed. (i.e., the partition ownership counts * will be within a delta of exactly one across all consumers.) * * For example, suppose there are two consumers C0 and C1, two topics t0 and t1, and each topic has 3 partitions, * resulting in partitions t0p0, t0p1, t0p2, t1p0, t1p1, and t1p2. * * The assignment will be: * C0: [t0p0, t0p2, t1p1] * C1: [t0p1, t1p0, t1p2] * * When subscriptions differ across consumer instances, the assignment process still considers each * consumer instance in round robin fashion but skips over an instance if it is not subscribed to * the topic. Unlike the case when subscriptions are identical, this can result in imbalanced * assignments. For example, we have three consumers C0, C1, C2, and three topics t0, t1, t2, * with 1, 2, and 3 partitions, respectively. Therefore, the partitions are t0p0, t1p0, t1p1, t2p0, * t2p1, t2p2. C0 is subscribed to t0; C1 is subscribed to t0, t1; and C2 is subscribed to t0, t1, t2. * * Tha assignment will be: * C0: [t0p0] * C1: [t1p0] * C2: [t1p1, t2p0, t2p1, t2p2] */
分区Rebalance(再均衡)
- 有新的消费者加入消费者群组
- 已有的消费者退出消费者群组
- 订阅的主题的分区发生变化
以上三种情况都会触发分区的重新分配,重新分配的过程叫Rebalance(再均衡)。
Rebalance给消费者群组带来了高可用性与伸缩性,但是在Rebalance期间,消费者无法读取消息,整个群组一小段时间不可用,而且当分区被重新分配给另一个消费者时,消费者当前的读取状态会丢失。
感觉问的比较简单,没有什么深入的了解。

浙公网安备 33010602011771号