七万号·数据平台实战手记

Back

查看Topic#

创建Topic#

删除Topic#

基本消费者代码#

更详细的消费控制#

指定分区#

    // 指定分区
String topic = "foo";
TopicPartition partition0 = new TopicPartition(topic, 0);
TopicPartition partition1 = new TopicPartition(topic, 1);
consumer.assign(Arrays.asList(partition0, partition1));
java

基本生产者#


Properties props = new Properties();
props.put("bootstrap.servers", "localhost:9092");
props.put("linger.ms", 1);
props.put("key.serializer", "org.apache.kafka.common.serialization.StringSerializer");
props.put("value.serializer", "org.apache.kafka.common.serialization.StringSerializer");


try(Producer<String, String> producer = new KafkaProducer<>(props)){
    for (int i = 0; i < 100; i++) {
        producer.send(new ProducerRecord<String, String>("quickstart-events", Integer.toString(i), Integer.toString(i)));
    }
    producer.flush();
}
java

事务#

Stream 基本结构#

Processor#

Topology use Processor#

Topology builder = new Topology();
    final StoreBuilder<KeyValueStore<String, Long>> countsStoreBuilder =
            Stores
                    .keyValueStoreBuilder(
                            Stores.persistentKeyValueStore("Counts"),
                            Serdes.String(),
                            Serdes.Long()
                    );
    builder.addSource("Source","source-topic")
            .addProcessor("Processor", () -> new WorldCountProcessor(),"Source")
            .addStateStore(countsStoreBuilder,"Process")
            .addSink("Sink","sink-topic","Process");
java

Kafka 设计思想#

https://kafka.apache.org/documentation/#design

Poll or Push#

Message Format#

log 文件#

log_file

Test Driver#

关于kafka那些不得不说的故事
https://realcpf.tech/blog/the-kafka
Author 刘佳成
Published at 2024年1月4日