我使用风暴卡夫卡来获得风暴0.10和卡夫卡0.9.0.0。每当我在集群上运行我的拓扑时,它就会从头开始读取,尽管我从属性文件中将zkRoot和consumer groupId作为 -
kafka.zkHosts=myserver.myhost.com:2181
kafka.topic=onboarding-mail-topic
kafka.zkRoot=/kafka-storm
kafka.group.id=onboarding
Spout:
BrokerHosts zkHosts = new ZkHosts(prop.getProperty("kafka.zkHosts"));
String topicName = prop.getProperty("kafka.topic");
String zkRoot = prop.getProperty("kafka.zkRoot");
String groupId = prop.getProperty("kafka.group.id");
//kafka spout conf
SpoutConfig kafkaConfig = new SpoutConfig(zkHosts, topicName, zkRoot, groupId);
kafkaConfig.scheme = new SchemeAsMultiScheme(new StringScheme());
KafkaSpout kafkaSpout = new KafkaSpout(kafkaConfig);
当我检查zookeeper ls /
时,它没有显示kafka-storm
[controller_epoch, controller, brokers, storm, zookeeper, kafka-manager, admin, isr_change_notification, consumers, config]
答案 0 :(得分:0)
最后,我想通了。因为从kafka读取并将偏移写回kafka是以不同的方式控制的。
如果您在风暴群集上运行拓扑,无论单个节点还是多个节点,请确保在storm.yaml文件中设置了以下内容
storm.zookeeper.servers
和
storm.zookeeper.port
除了zkHosts和zkRoot以及消费者群组ID之外的属性。
或者最佳做法是在创建KafkaSpout时通过设置正确的值来覆盖拓扑中的这些属性,如< - p>
BrokerHosts zkHosts = new ZkHosts(prop.getProperty("kafka.zkHosts"));
String topicName = prop.getProperty("kafka.topic");
String zkRoot = prop.getProperty("kafka.zkRoot");
String groupId = prop.getProperty("kafka.group.id");
String kafkaServers = prop.getProperty("kafka.zkServers");
String zkPort = prop.getProperty("kafka.zkPort");
//kafka spout conf
SpoutConfig kafkaConfig = new SpoutConfig(zkHosts, topicName, zkRoot, groupId);
kafkaConfig.scheme = new SchemeAsMultiScheme(new StringScheme());
kafkaConfig.zkServers = Arrays.asList(kafkaServers);
kafkaConfig.zkPort = Integer.valueOf(zkPort);
KafkaSpout kafkaSpout = new KafkaSpout(kafkaConfig);
甚至可以将这些值放在Config对象中。这是更好的,因为您可能希望将偏移信息存储到其他一些zookeeper集群,而拓扑从完全不同的代理中读取消息
用于理解的KafkaSpout代码段 -
@Override
public void open(Map conf, final TopologyContext context, final SpoutOutputCollector collector) {
_collector = collector;
Map stateConf = new HashMap(conf);
List<String> zkServers = _spoutConfig.zkServers;
if (zkServers == null) {
zkServers = (List<String>) conf.get(Config.STORM_ZOOKEEPER_SERVERS);
}
Integer zkPort = _spoutConfig.zkPort;
if (zkPort == null) {
zkPort = ((Number) conf.get(Config.STORM_ZOOKEEPER_PORT)).intValue();
}
stateConf.put(Config.TRANSACTIONAL_ZOOKEEPER_SERVERS, zkServers);
stateConf.put(Config.TRANSACTIONAL_ZOOKEEPER_PORT, zkPort);
stateConf.put(Config.TRANSACTIONAL_ZOOKEEPER_ROOT, _spoutConfig.zkRoot);
_state = new ZkState(stateConf);
_connections = new DynamicPartitionConnections(_spoutConfig, KafkaUtils.makeBrokerReader(conf, _spoutConfig));
// using TransactionalState like this is a hack
int totalTasks = context.getComponentTasks(context.getThisComponentId()).size();
if (_spoutConfig.hosts instanceof StaticHosts) {
_coordinator = new StaticCoordinator(_connections, conf, _spoutConfig, _state, context.getThisTaskIndex(), totalTasks, _uuid);
} else {
_coordinator = new ZkCoordinator(_connections, conf, _spoutConfig, _state, context.getThisTaskIndex(), totalTasks, _uuid);
}