use of org.apache.storm.trident.Stream in project storm by apache.
the class TridentFileTopology method buildTopology.
public static StormTopology buildTopology(String hdfsUrl) {
FixedBatchSpout spout = new FixedBatchSpout(new Fields("sentence", "key"), 1000, new Values("the cow jumped over the moon", 1L), new Values("the man went to the store and bought some candy", 2L), new Values("four score and seven years ago", 3L), new Values("how many apples can you eat", 4L), new Values("to be or not to be the person", 5L));
spout.setCycle(true);
TridentTopology topology = new TridentTopology();
Stream stream = topology.newStream("spout1", spout);
Fields hdfsFields = new Fields("sentence", "key");
FileNameFormat fileNameFormat = new DefaultFileNameFormat().withPath("/tmp/trident").withPrefix("trident").withExtension(".txt");
RecordFormat recordFormat = new DelimitedRecordFormat().withFields(hdfsFields);
FileRotationPolicy rotationPolicy = new FileSizeRotationPolicy(5.0f, FileSizeRotationPolicy.Units.MB);
HdfsState.Options options = new HdfsState.HdfsFileOptions().withFileNameFormat(fileNameFormat).withRecordFormat(recordFormat).withRotationPolicy(rotationPolicy).withFsUrl(hdfsUrl).withConfigKey("hdfs.config");
StateFactory factory = new HdfsStateFactory().withOptions(options);
TridentState state = stream.partitionPersist(factory, hdfsFields, new HdfsUpdater(), new Fields());
return topology.build();
}
use of org.apache.storm.trident.Stream in project storm by apache.
the class UserPersistenceTridentTopology method getTopology.
@Override
public StormTopology getTopology() {
TridentTopology topology = new TridentTopology();
JdbcState.Options options = new JdbcState.Options().withConnectionProvider(connectionProvider).withMapper(this.jdbcMapper).withJdbcLookupMapper(new SimpleJdbcLookupMapper(new Fields("dept_name"), Lists.newArrayList(new Column("user_id", Types.INTEGER)))).withTableName(TABLE_NAME).withSelectQuery(SELECT_QUERY);
JdbcStateFactory jdbcStateFactory = new JdbcStateFactory(options);
Stream stream = topology.newStream("userSpout", new UserSpout());
TridentState state = topology.newStaticState(jdbcStateFactory);
stream = stream.stateQuery(state, new Fields("user_id", "user_name", "create_date"), new JdbcQuery(), new Fields("dept_name"));
stream.partitionPersist(jdbcStateFactory, new Fields("user_id", "user_name", "dept_name", "create_date"), new JdbcUpdater(), new Fields());
return topology.build();
}
use of org.apache.storm.trident.Stream in project storm by apache.
the class TridentKafkaConsumerTopology method newTopology.
/**
* Creates a new topology that prints inputs to stdout.
* @param tridentSpout The spout to use
*/
public static StormTopology newTopology(ITridentDataSource tridentSpout) {
final TridentTopology tridentTopology = new TridentTopology();
final Stream spoutStream = tridentTopology.newStream("spout", tridentSpout).parallelismHint(2);
spoutStream.each(spoutStream.getOutputFields(), new Debug(false));
return tridentTopology.build();
}
use of org.apache.storm.trident.Stream in project storm by apache.
the class TridentEsTopology method main.
/**
* The example's main method.
* @param args the command line arguments
* @throws AlreadyAliveException if the topology is already started
* @throws InvalidTopologyException if the topology is invalid
* @throws AuthorizationException if the topology authorization fails
*/
public static void main(final String[] args) throws AlreadyAliveException, InvalidTopologyException, AuthorizationException {
int batchSize = BATCH_SIZE_DEFAULT;
FixedBatchSpout spout = new FixedBatchSpout(batchSize);
spout.cycle = true;
TridentTopology topology = new TridentTopology();
Stream stream = topology.newStream("spout", spout);
EsConfig esConfig = new EsConfig("http://localhost:9300");
Fields esFields = new Fields("index", "type", "source");
EsTupleMapper tupleMapper = EsTestUtil.generateDefaultTupleMapper();
StateFactory factory = new EsStateFactory(esConfig, tupleMapper);
TridentState state = stream.partitionPersist(factory, esFields, new EsUpdater(), new Fields());
EsTestUtil.startEsNode();
EsTestUtil.waitForSeconds(EsConstants.WAIT_DEFAULT_SECS);
StormSubmitter.submitTopology(TOPOLOGY_NAME, new Config(), topology.build());
}
use of org.apache.storm.trident.Stream in project storm by apache.
the class WordCountTrident method buildTopology.
public static StormTopology buildTopology(String url, String collectionName) {
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);
MongoMapper mapper = new SimpleMongoMapper().withFields("word", "count");
MongoState.Options options = new MongoState.Options().withUrl(url).withCollectionName(collectionName).withMapper(mapper);
StateFactory factory = new MongoStateFactory(options);
TridentTopology topology = new TridentTopology();
Stream stream = topology.newStream("spout1", spout);
stream.partitionPersist(factory, fields, new MongoStateUpdater(), new Fields());
TridentState state = topology.newStaticState(factory);
stream = stream.stateQuery(state, new Fields("word"), new MongoStateQuery(), new Fields("columnName", "columnValue"));
stream.each(new Fields("word", "columnValue"), new PrintFunction(), new Fields());
return topology.build();
}
Aggregations