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)
  • 相关阅读:
    e.target和e.event和event.srcElement
    js代码优化
    史上最全的CSS hack方式一览
    学习NodeJS第一天:node.js引言
    响应式布局
    HTML+CSS编写规范
    英文SEO外部链接资源收集之常用的footprints
    判别木马
    php简单命令代码集锦
    zencart 新页面调用好功能代码集:
  • 原文地址:https://www.cnblogs.com/allenwas3/p/9681783.html
Copyright © 2011-2022 走看看