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)
  • 相关阅读:
    URL中#号(井号)的作用
    Sublime Text2 快捷键汇总
    Sublime Text2 使用及插件配置
    Sumblime Text 2 常用插件以及安装方法
    CSS禁止选择文本功能(兼容IE,火狐等浏览器)
    JavaScript 判断 URL
    纯真IP数据库格式读取方法(JAVA/PHP/Python)
    Sublime Text 2 性感无比的代码编辑器!程序员必备神器!跨平台支持Win/Mac/Linux
    base64:URL背景图片与web页面性能优化
    数独DFS实现
  • 原文地址:https://www.cnblogs.com/allenwas3/p/9681783.html
Copyright © 2011-2022 走看看