use of org.apache.storm.rocketmq.common.selector.DefaultTopicSelector 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();
}
use of org.apache.storm.rocketmq.common.selector.DefaultTopicSelector in project storm by apache.
the class WordCountTrident method buildTopology.
public static StormTopology buildTopology(String nameserverAddr, String topic) {
Fields fields = new Fields("word", "count");
FixedBatchSpout spout = new FixedBatchSpout(fields, 4, new Values("storm", 1), new Values("trident", 1), new Values("needs", 1), new Values("javadoc", 1));
spout.setCycle(true);
TupleToMessageMapper mapper = new FieldNameBasedTupleToMessageMapper("word", "count");
TopicSelector selector = new DefaultTopicSelector(topic);
Properties properties = new Properties();
properties.setProperty(RocketMqConfig.NAME_SERVER_ADDR, nameserverAddr);
RocketMqState.Options options = new RocketMqState.Options().withMapper(mapper).withSelector(selector).withProperties(properties);
StateFactory factory = new RocketMqStateFactory(options);
TridentTopology topology = new TridentTopology();
Stream stream = topology.newStream("spout1", spout);
stream.partitionPersist(factory, fields, new RocketMqStateUpdater(), new Fields());
return topology.build();
}
use of org.apache.storm.rocketmq.common.selector.DefaultTopicSelector in project storm by apache.
the class RocketMqBoltTest method setUp.
@Before
public void setUp() throws Exception {
rocketMqBolt = new RocketMqBolt();
rocketMqBolt.withSelector(new DefaultTopicSelector("tpc"));
rocketMqBolt.withMapper(new FieldNameBasedTupleToMessageMapper("f1", "f2"));
rocketMqBolt.withBatch(false);
rocketMqBolt.withBatchSize(5);
rocketMqBolt.withAsync(true);
rocketMqBolt.withFlushIntervalSecs(5);
producer = mock(DefaultMQProducer.class);
TestUtils.setFieldValue(rocketMqBolt, "producer", producer);
}
Aggregations