c# rdkafka 設置偏移量(offset)

參考資料:this

  librdkafka: 如何設置Kafka消費者訂閱消息的起始偏移位置spa

領導要求kafka消費者端消費最新的數據。.net

不知道怎麼設置偏移量,查了資料。code

用慣了封裝好的東西,都不知道怎麼設置了,看了源代碼以及參考資料,才知道本身動手寫。blog

var config = new Config { GroupId = UtilityConfig._groupId, EnableAutoCommit = true, StatisticsInterval = TimeSpan.FromSeconds(6), ["auto.offset.reset"] = "lastest" //設置獲取最新的消息,要設置什麼去官方文檔找,直接經過key-value方式設置便可
 }; using (var consumer = new EventConsumer(config, UtilityConfig._brokerlist)) { //代碼邏輯

config部分源碼索引

 

public string this[string name] { set { this.handle.Set(name, value); } get { return this.handle.Get(name); } } public string GroupId { set { this["group.id"] = value; } get { return this["group.id"]; } } public bool EnableAutoCommit { set { this["enable.auto.commit"] = value ? "true" : "false"; } get { return this["enable.auto.commit"] == "true"; } }

 

 

 

從源碼能夠看出config裏面的EnableAutoCommit屬性是本身封裝的,因此要設置什麼屬性就本身經過索引器設置。文檔

 

你們千萬不要想着偷懶吶。get

相關文章
相關標籤/搜索