kafka简记

专注于吞吐量的mq.
组成:
1.zookeeper 集群化
2.broker 集群化
3.producer
4.consumer

消息发送流程:
消息–>写入到按分区的缓存–>sender任务执行–>批量发送(合并请求提高吞吐量)

生产者使用模式:
1.多线程单个生产者,使用简单
2.多线程多生产者
消费者模式:
1.多消费者模式可自动ack
2.全局消费者,多work模式,手动ack

topic主题分区
kafka采用同一个topic多个分区模式提高吞吐量,生产端可以配置自定义分区方式:

public interface Partitioner extends Configurable, Closeable {

    /**
     * Compute the partition for the given record.
     *
     * @param topic The topic name
     * @param key The key to partition on (or null if no key)
     * @param keyBytes The serialized key to partition on( or null if no key)
     * @param value The value to partition on or null
     * @param valueBytes The serialized value to partition on or null
     * @param cluster The current cluster metadata
     */
    public int partition(String topic, Object key, byte[] keyBytes, Object value, byte[] valueBytes, Cluster cluster);

    /**
     * This is called when partitioner is closed.
     */
    public void close();

}

集群消费:同一个消费组订阅同主题
广播消费:不同消费组订阅主题

消息分发方式:对于订阅主题的消费组,每个组都会收到每一条消息;

猜你喜欢

转载自blog.csdn.net/strive____/article/details/94647398