Home | 简体中文 | 繁体中文 | 杂文 | 打赏(Donations) | 云栖社区 | OSChina 博客 | Facebook | Linkedin | 知乎专栏 | Github | Search | About

28.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();