编辑:我在bolt中添加了一个.ack()(这要求我使用一个富bolt而不是基本的bolt),并且遇到了相同的问题-没有任何东西告诉我元组正在被bolt处理。
如果有关系的话,我在ec2示例的centos映像上运行这个。任何帮助都将不胜感激。
我正在尝试建立一个非常基本的helloworld风暴示例,从kafka集群读取消息,并打印/记录收到的消息。
目前我有20个消息在Kafka集群。当我运行拓扑结构(它看起来刚刚开始),我可以看到我的Kafka喷口以及回声螺栓。在Storm中,Kafka喷口 Acked
列的值为20—我假设是它能够读取/访问的消息数(?)
然而,echobolt行只注意到我有1个执行者和1个任务。所有其他列均为0。
查看生成的storm worker日志,我看到以下行: 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}}
worker日志的其余部分没有显示bolt处理的消息的日志/打印输出。我不明白为什么博尔特似乎没有从Kafka星团得到任何信息。任何帮助都会很好。谢谢。
建造Kafka城堡
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) {}
}
2条答案
按热度按时间ua4mk5z41#
您需要在bolt中对元组调用ack或fail,否则spout不知道元组已被完全处理。这将导致您看到的计数问题。
km0tfn4u2#
答案很简单。我从来没有告诉博尔特该订阅哪条流。添加
.shuffleGrouping("Kafka Spout");
解决了这个问题。