Search in sources :

Example 1 with EsTupleMapper

use of org.apache.storm.elasticsearch.common.EsTupleMapper in project storm by apache.

the class TridentEsTopology method main.

public static void main(String[] args) throws Exception {
    int batchSize = 100;
    FixedBatchSpout spout = new FixedBatchSpout(batchSize);
    spout.setCycle(true);
    TridentTopology topology = new TridentTopology();
    Stream stream = topology.newStream("spout", spout);
    EsConfig esConfig = new EsConfig(EsConstants.clusterName, new String[] { "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(5);
    try (LocalCluster cluster = new LocalCluster();
        LocalTopology topo = cluster.submitTopology(TOPOLOGY_NAME, null, topology.build())) {
        EsTestUtil.waitForSeconds(20);
    }
    System.exit(0);
}
Also used : LocalCluster(org.apache.storm.LocalCluster) TridentState(org.apache.storm.trident.TridentState) LocalTopology(org.apache.storm.LocalCluster.LocalTopology) EsConfig(org.apache.storm.elasticsearch.common.EsConfig) Fields(org.apache.storm.tuple.Fields) StateFactory(org.apache.storm.trident.state.StateFactory) TridentTopology(org.apache.storm.trident.TridentTopology) EsTupleMapper(org.apache.storm.elasticsearch.common.EsTupleMapper) Stream(org.apache.storm.trident.Stream)

Example 2 with EsTupleMapper

use of org.apache.storm.elasticsearch.common.EsTupleMapper in project storm by apache.

the class EsIndexTopology method main.

public static void main(String[] args) throws Exception {
    Config config = new Config();
    config.setNumWorkers(1);
    TopologyBuilder builder = new TopologyBuilder();
    UserDataSpout spout = new UserDataSpout();
    builder.setSpout(SPOUT_ID, spout, 1);
    EsTupleMapper tupleMapper = EsTestUtil.generateDefaultTupleMapper();
    EsConfig esConfig = new EsConfig(EsConstants.clusterName, new String[] { "localhost:9300" });
    builder.setBolt(BOLT_ID, new EsIndexBolt(esConfig, tupleMapper), 1).shuffleGrouping(SPOUT_ID);
    EsTestUtil.startEsNode();
    EsTestUtil.waitForSeconds(5);
    try (LocalCluster cluster = new LocalCluster();
        LocalTopology topo = cluster.submitTopology(TOPOLOGY_NAME, config, builder.createTopology())) {
        EsTestUtil.waitForSeconds(20);
    }
    System.exit(0);
}
Also used : LocalCluster(org.apache.storm.LocalCluster) EsConfig(org.apache.storm.elasticsearch.common.EsConfig) TopologyBuilder(org.apache.storm.topology.TopologyBuilder) EsTupleMapper(org.apache.storm.elasticsearch.common.EsTupleMapper) Config(org.apache.storm.Config) EsConfig(org.apache.storm.elasticsearch.common.EsConfig) LocalTopology(org.apache.storm.LocalCluster.LocalTopology)

Aggregations

LocalCluster (org.apache.storm.LocalCluster)2 LocalTopology (org.apache.storm.LocalCluster.LocalTopology)2 EsConfig (org.apache.storm.elasticsearch.common.EsConfig)2 EsTupleMapper (org.apache.storm.elasticsearch.common.EsTupleMapper)2 Config (org.apache.storm.Config)1 TopologyBuilder (org.apache.storm.topology.TopologyBuilder)1 Stream (org.apache.storm.trident.Stream)1 TridentState (org.apache.storm.trident.TridentState)1 TridentTopology (org.apache.storm.trident.TridentTopology)1 StateFactory (org.apache.storm.trident.state.StateFactory)1 Fields (org.apache.storm.tuple.Fields)1