zoukankan      html  css  js  c++  java
  • kafka producer 发送消息简介

    kafka 的 topic 由 partition 组成,producer 会根据 key,选择一个 partition 发送消息,而 partition 有多个副本,副本有 leader 和 follower 之分,producer 需要把消息发送到 partition 的 leader。

    背景:kafka 集群由 3 个节点组成(node1,node2,node3,其中 node3 是 controller),存在名为 idea-zhang 的 topic,只有一个 partition, partition 的副本数是2。

    流程图如下:

    重要日志如下:

    Initialize connection to node 10.253.114.163:9092 (id: -1 rack: null) for sending metadata request (org.apache.kafka.clients.NetworkClient)
    Sending metadata request (type=MetadataRequest, topics=idea-zhang) to node 10.253.114.163:9092 (id: -1 rack: null) (org.apache.kafka.clients.NetworkClient)
    
    Completed receive from node -1 for METADATA with correlation id 1, received 
    {
    	throttle_time_ms = 0,
    	brokers = [{
    		node_id = 2,
    		host = 10.253.162.17,
    		port = 9092,
    		rack = null
    	},
    	{
    		node_id = 1,
    		host = 10.253.160.154,
    		port = 9092,
    		rack = null
    	},
    	{
    		node_id = 3,
    		host = 10.253.114.163,
    		port = 9092,
    		rack = null
    	}],
    	cluster_id = oX31KEPESLeIWHz7BgJv7g,
    	controller_id = 3,
    	topic_metadata = [{
    		error_code = 0,
    		topic = idea-zhang,
    		is_internal = false,
    		partition_metadata = [{
    			error_code = 0,
    			partition = 0,
    			leader = 2,
    			replicas = [2, 3],
    			isr = [2, 3]
    		}]
    	}]
    }
     (org.apache.kafka.clients.NetworkClient)
     
     Initiating connection to node 10.253.162.17:9092 (id: 2 rack: null) (org.apache.kafka.clients.NetworkClient)
     
     Sending record ProducerRecord(topic=idea-zhang, partition=null, headers=RecordHeaders(headers = [], isReadOnly = true), key=1, value=Message_1, timestamp=null) with callback null to topic idea-zhang partition 0 (org.apache.kafka.clients.producer.KafkaProducer)
  • 相关阅读:
    学习Kubernetes,这些负载均衡知识点得知道!
    Nginx请求处理流程
    字节跳动面试题+答案,答对了30+
    Cache 和 Buffer 的区别在哪里
    优化你的HTTPS(下),你需要这么做
    优化你的HTTPS(上),你需要这么做
    swift之Mac中NSSplitView的简单实用
    oc之mac中- NSBox
    Mac之NSImageView的简单实用
    swift之预防 Timer 的循环引用
  • 原文地址:https://www.cnblogs.com/allenwas3/p/9681783.html
Copyright © 2011-2022 走看看