use of org.apache.storm.rocketmq.spout.RocketMqSpout in project storm by apache.
the class WordCountTopology method buildTopology.
public static StormTopology buildTopology(String nameserverAddr, String topic) {
Properties properties = new Properties();
properties.setProperty(SpoutConfig.NAME_SERVER_ADDR, nameserverAddr);
properties.setProperty(SpoutConfig.CONSUMER_GROUP, CONSUMER_GROUP);
properties.setProperty(SpoutConfig.CONSUMER_TOPIC, CONSUMER_TOPIC);
RocketMqSpout spout = new RocketMqSpout(properties);
TupleToMessageMapper mapper = new FieldNameBasedTupleToMessageMapper("word", "count");
TopicSelector selector = new DefaultTopicSelector(topic);
properties = new Properties();
properties.setProperty(RocketMqConfig.NAME_SERVER_ADDR, nameserverAddr);
RocketMqBolt insertBolt = new RocketMqBolt().withMapper(mapper).withSelector(selector).withProperties(properties);
// wordSpout ==> countBolt ==> insertBolt
TopologyBuilder builder = new TopologyBuilder();
WordCounter bolt = new WordCounter();
builder.setSpout(WORD_SPOUT, spout, 1);
builder.setBolt(COUNT_BOLT, bolt, 1).fieldsGrouping(WORD_SPOUT, new Fields("str"));
builder.setBolt(INSERT_BOLT, insertBolt, 1).shuffleGrouping(COUNT_BOLT);
return builder.createTopology();
}
Aggregations