KafkaSpout是一個與Storm集成的噴口實現,可以從Kafka集群中讀取消息,然後在Storm生態係統中以元組的形式發出這些消息。下麵是創建一個簡單的KafkaSpout的示例代碼
// ZooKeeper連接字符串
BrokerHosts hosts = new ZkHosts(zkConnString);
//創建SpoutConfig對象
SpoutConfig SpoutConfig = new SpoutConfig(主機,
topicName, "/" + topicName UUID.randomUUID().toString());
//將ByteBuffer轉換為String。
spoutConfig。scheme = new SchemeAsMultiScheme(new StringScheme());
//分配SpoutConfig到KafkaSpout。
KafkaSpout KafkaSpout = new KafkaSpout(spoutConfig);