编辑:我在Bolt上添加了一个.ack()(要求我使用Rich Bolt而不是基本的螺栓)并且遇到了同样的问题 - 没有任何东西可以告诉我元组正由螺栓处理。 / p>
如果重要,我在EC2实例上的CentOS映像上运行它。任何帮助将不胜感激。
我正在尝试设置一个非常基本的HelloWorld Storm示例来读取来自Kafka群集的消息并打印/记录我得到的消息。
目前我在Kafka群集中有20条消息。当我运行拓扑(似乎开始很好)时,我能够看到我的Kafka Spout以及Echo Bolt。在Storm UI中,Kafka Spout Acked
列有20个作为值 - 我假设它是能够读取/访问的消息数(?)
查看生成的Storm工作日志,我看到以下行:Read partition information from: /HelloWorld Spout/partition_0 --> {"topic":"helloworld","partition":0,"topology":{"id":"<UUID>","name":"Kafka-Storm test"},"broker":{"port":6667,"host":"ip-10-0-0-35.ec2.internal"},"offset":20}
接下来的几行如下:
s.k.PartitionManager [INFO] Last commit offset from zookeeper: 0
s.k.PartitionManager [INFO] Commit offset 0 is more than 9223372036854775807 behind, resetting to startOffsetTime=-2
s.k.PartitionManager [INFO] Starting Kafka ip-10-0-0-35.ec2.internal:0 from offset 0
s.k.ZkCoordinator [INFO] Task [1/1] Finished refreshing
s.k.ZkCoordinator [INFO] Task [1/1] Refreshing partition manager connections
s.k.DynamicBrokersReader [INFO] Read partition info from zookeeper: GlobalPartitionInformation{partitionMap={0=ip-10-0-0-35.ec2.internal:6667}}
工作日志的其余部分显示Bolt处理的消息没有记录/打印。我不知道为什么Bolt似乎没有从Kafka集群获得任何消息。任何帮助都会很棒。感谢。
构建KafkaSpout
private static KafkaSpout setupSpout() {
BrokerHosts hosts = new ZkHosts("localhost:2181");
SpoutConfig spoutConfig = new SpoutConfig(hosts, "helloworld", "", "HelloWorld Spout");
spoutConfig.scheme = new SchemeAsMultiScheme(new StringScheme());
spoutConfig.forceFromStart = true;
spoutConfig.startOffsetTime = kafka.api.OffsetRequest.EarliestTime();
return new KafkaSpout(spoutConfig);
}
构建拓扑并提交
public static void main(String[] args) {
TopologyBuilder builder = new TopologyBuilder();
builder.setSpout("Kafka Spout", setupSpout());
builder.setBolt("Echo Bolt", new SystemOutEchoBolt());
try {
System.setProperty("storm.jar", "/tmp/storm.jar");
StormSubmitter.submitTopology("Kafka-Storm test", new Config(), builder.createTopology());
} //catchExceptionsHere
}
螺栓
public class SystemOutEchoBolt extends BaseRichBolt {
private static final long serialVersionUID = 1L;
private static final Logger logger = LoggerFactory.getLogger(SystemOutEchoBolt.class);
private OutputCollector m_collector;
@SuppressWarnings("rawtypes")
@Override
public void prepare(Map _map, TopologyContext _conetxt, OutputCollector _collector) {
m_collector = _collector;
}
@Override
public void execute(Tuple _tuple) {
System.out.println("Printing tuple with toString(): " + _tuple.toString());
System.out.println("Printing tuple with getString(): " + _tuple.getString(0));
logger.info("Logging tuple with logger: " + _tuple.getString(0));
m_collector.ack(_tuple);
}
@Override
public void declareOutputFields(OutputFieldsDeclarer _declarer) {}
}
答案 0 :(得分:2)
答案很简单。我从来没有告诉过哪个流可以订阅。添加.shuffleGrouping("Kafka Spout");
解决了问题。
答案 1 :(得分:0)
您需要在螺栓中的元组上调用ack或失败,否则spout不知道元组已经完全处理。这将导致您看到的计数问题。
public class SystemOutEchoBolt extends BaseBasicBolt {
private static final long serialVersionUID = 1L;
private static final Logger logger = LoggerFactory.getLogger(SystemOutEchoBolt.class);
@Override
public void execute(Tuple _tuple, BasicOutputCollector _collector) {
System.out.println("Printing tuple with toString(): " + _tuple.toString());
System.out.println("Printing tuple with getString(): " + _tuple.getString(0));
logger.info("Logging tuple with logger: " + _tuple.getString(0));
_collector.ack(_tuple);
}
@Override
public void declareOutputFields(OutputFieldsDeclarer arg0) {}
}
}