Home | 簡體中文 | 繁體中文 | 雜文 | 知乎專欄 | Github | OSChina 博客 | 雲社區 | 雲棲社區 | Facebook | Linkedin | 視頻教程 | 打賞(Donations) | About
知乎專欄多維度架構 | 微信號 netkiller-ebook | QQ群:128659835 請註明“讀者”

26.3. 啟動 kafka

有兩種方式啟動 kafka, 一種是命令行,另一種是通過 Java 程序,命令行方式請參考《Netkiller Linux 手札》,這裡只介紹如何使用 Java 程序啟動 Kafka。

首先啟動 Zookeeper

		
QuorumPeerConfig config = new QuorumPeerConfig();
InputStream inputStream = KafkaTest.class.getResourceAsStream("/srv/kafka/config/zookeeper.properties");
Properties properties = new Properties();	    
properties.load(inputStream);
inputStream.close();
config.parseProperties(properties);
ServerConfig   serverConfig = new ServerConfig();
serverConfig.readFrom(config);
new ZooKeeperServerMain().runFromConfig(serverConfig);		
		
		

然後啟動 Kafka

		
InputStream inputStream = KafkaTest.class.getResourceAsStream("/srv/kafka/config/server.properties");
Properties properties = new Properties();
properties.load(is);
inputStream.close();
KafkaServerStartable kafkaServerStartable = KafkaServerStartable.fromProps(properties);
kafkaServerStartable.startup();
kafkaServerStartable.awaitShutdown();