2016-06-08 73 views
0

我正在使用kafka 2.10-0.9.0.1 當我通過命令刪除主題並標記爲刪除主題時。卡夫卡:如何刪除主題工作

bin/kafka-topics.sh --zookeeper localhost:2181 --delete --topic T.AB_KAFF 

然而,當我將消息發佈到這個話題,當我訂閱了這個話題再次,主題描述說,它的滯後-ve的什麼電流偏移量(上次提交的偏移量)

bin/kafka-consumer-groups.sh --new-consumer --bootstrap-server localhost:9092 --describe --group G.AB_KAFF 

最後一個主題的狀態:

羣組,主題,分區,電流偏移量,LOG END OFFSET,LAG,OWNER G.AB_KAFF,T.AB_KAFF,0,5,5,0,消費者2_/127.0.0.1 G.AB_KAFF, T.AB_KAFF,1,5,5,0,消費者-2_/127.0.0.1

現在我刪除話題。 並再次訂閱後發佈消息到這個話題的話題

國家:

羣組,主題,分區,電流偏移量,LOG END OFFSET,LAG,OWNER G.AB_KAFF,T.AB_KAFF,0 ,5,1,-4,消費者3_/127.0.0.1 G.AB_KAFF, T.AB_KAFF,1,5,0,-5,消費者3_/127.0.0.1

那麼,爲什麼卡夫卡將滯後設置爲-ve數。 這不是可能導致問題嗎?

假設我重新訂閱刪除的話題,所以我將不會得到任何消息,直到其-ve滯後0

其他信息:
- 我在我的本地
運行3個卡夫卡節點 - 我添加了屬性:delete.topic.enable = true
- 本主題是使用partition = 2,replication-factor = 2創建的

+0

您是否嘗試刪除該主題,一旦你已經在'broker'配置文件中添加'delete.topic.enable'。 ? – Kulasangar

+0

是的,我已經在我的server.properties文件中添加了此屬性 – nikhil7610

+0

'-ve lag'是什麼意思?你的主題是否被刪除? – Kulasangar

回答

1

一旦刪除了一個主題,它就會丟失存儲在Kafka中的記錄。因此,對最新抵消的查詢返回0

組中的消費者實例定期提交最後一個讀取記錄偏移量,該偏移量位於特殊主題__consumer-offset-{0..49}中。在延遲計算期間,它會執行latestOffset-lastReadRecordOffset,因此在主題刪除後kafka-consumers-groups命令中顯示負滯後。

[[email protected] bin]$ sh kafka-run-class.sh kafka.tools.GetOffsetShell --topic test --time -1 --broker-list localhost:9092 # Query to get latest offset 
test:0:1000 
[[email protected] bin]$ sh kafka-topics.sh --topic test --zookeeper localhost:2181 --delete 
Topic test is marked for deletion. 
Note: This will have no impact if delete.topic.enable is not set to true. 
[[email protected] bin]$ sh kafka-run-class.sh kafka.tools.GetOffsetShell --topic test --time -1 --broker-list localhost:9092 # After deletion 
[[email protected] bin]$ 

存儲在Zookeeper中的元數據將被異步刪除。 (糾正我,如果我錯了)

[[email protected] bin]$ sh zookeeper-shell.sh localhost:2181 
Connecting to localhost:2181 
Welcome to ZooKeeper! 
JLine support is disabled 

WATCHER:: 

WatchedEvent state:SyncConnected type:None path:null 
get /brokers/topics/test/partitions/0/state 
{"controller_epoch":1,"leader":0,"version":1,"leader_epoch":0,"isr":[0]} 
cZxid = 0x13c 
ctime = Thu Jun 09 09:56:05 IST 2016 
mZxid = 0x13c 
mtime = Thu Jun 09 09:56:05 IST 2016 
pZxid = 0x13c 
cversion = 0 
dataVersion = 0 
aclVersion = 0 
ephemeralOwner = 0x0 
dataLength = 72 
numChildren = 0 
+0

那麼有沒有什麼辦法可以刪除這個話題,以至於根本就沒有收到消息? – nikhil7610

+0

在代理中禁用'auto.create.topics.enable'屬性。 小心:此屬性在默認情況下處於啓用狀態。從生產者/消費者到不存在的主題的請求會自動創建。如果要禁用它,請確保在啓動客戶端應用程序之前創建了所需的主題。 –

+0

謝謝@kamal。我想知道如何通過使用者組或主題工具在運行時刪除主題。這在重新啓動我的應用程序時會很有幫助。 – nikhil7610