Search in sources :

Example 1 with RocketMqBolt

use of org.apache.storm.rocketmq.bolt.RocketMqBolt 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();
}
Also used : FieldNameBasedTupleToMessageMapper(org.apache.storm.rocketmq.common.mapper.FieldNameBasedTupleToMessageMapper) Fields(org.apache.storm.tuple.Fields) TupleToMessageMapper(org.apache.storm.rocketmq.common.mapper.TupleToMessageMapper) FieldNameBasedTupleToMessageMapper(org.apache.storm.rocketmq.common.mapper.FieldNameBasedTupleToMessageMapper) RocketMqBolt(org.apache.storm.rocketmq.bolt.RocketMqBolt) TopologyBuilder(org.apache.storm.topology.TopologyBuilder) TopicSelector(org.apache.storm.rocketmq.common.selector.TopicSelector) DefaultTopicSelector(org.apache.storm.rocketmq.common.selector.DefaultTopicSelector) RocketMqSpout(org.apache.storm.rocketmq.spout.RocketMqSpout) DefaultTopicSelector(org.apache.storm.rocketmq.common.selector.DefaultTopicSelector) Properties(java.util.Properties)

Aggregations

Properties (java.util.Properties)1 RocketMqBolt (org.apache.storm.rocketmq.bolt.RocketMqBolt)1 FieldNameBasedTupleToMessageMapper (org.apache.storm.rocketmq.common.mapper.FieldNameBasedTupleToMessageMapper)1 TupleToMessageMapper (org.apache.storm.rocketmq.common.mapper.TupleToMessageMapper)1 DefaultTopicSelector (org.apache.storm.rocketmq.common.selector.DefaultTopicSelector)1 TopicSelector (org.apache.storm.rocketmq.common.selector.TopicSelector)1 RocketMqSpout (org.apache.storm.rocketmq.spout.RocketMqSpout)1 TopologyBuilder (org.apache.storm.topology.TopologyBuilder)1 Fields (org.apache.storm.tuple.Fields)1