Java Code Examples for org.apache.storm.jdbc.common.ConnectionProvider

The following examples show how to use org.apache.storm.jdbc.common.ConnectionProvider. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
@Bean("wordCountToMySQLBolt")
    public JdbcInsertBolt buildBolt() {

        super.setId("wordCountToMySQLBolt");

        Map hikariConfigMap = Maps.newHashMap();
        hikariConfigMap.put("dataSourceClassName", mySQLProps.getDataSourceClassName());
        hikariConfigMap.put("dataSource.url", mySQLProps.getDataSourceUrl());
        hikariConfigMap.put("dataSource.user", mySQLProps.getDataSourceUser());
        hikariConfigMap.put("dataSource.password", mySQLProps.getDataSourcePassword());
        ConnectionProvider connectionProvider = new HikariCPConnectionProvider(hikariConfigMap);

        List<Column> columnSchema = Lists.newArrayList(
                new Column("targetDate", Types.DATE),
                new Column("word", java.sql.Types.VARCHAR),
                new Column("count", Types.BIGINT),
                new Column("count_0", Types.BIGINT)
        );
//        JdbcMapper simpleJdbcMapper = new SimpleJdbcMapper(tableName, connectionProvider);
        JdbcMapper simpleJdbcMapper = new SimpleJdbcMapper(columnSchema);
        JdbcInsertBolt insertBolt = new JdbcInsertBolt(connectionProvider, simpleJdbcMapper)
                .withInsertQuery(insertQuery)
                .withQueryTimeoutSecs(queryTimeoutSecs);
        return insertBolt;
    }
 
Example 2
public static void main(String[] args) {
    //根据Spout和Bolt构建TopologyBuilder
    TopologyBuilder builder = new TopologyBuilder();
    builder.setSpout("DataSourceSpout", new DataSourceSpout());
    builder.setBolt("SplitBolt", new SplitBolt()).shuffleGrouping("DataSourceSpout");
    builder.setBolt("CountBolt", new CountBolt()).shuffleGrouping("SplitBolt");

    Map hikariConfigMap = Maps.newHashMap();
    hikariConfigMap.put("dataSourceClassName","com.mysql.jdbc.jdbc2.optional.MysqlDataSource");
    hikariConfigMap.put("dataSource.url", "jdbc:mysql://192.168.60.11/storm");
    hikariConfigMap.put("dataSource.user","root");
    hikariConfigMap.put("dataSource.password","123");
    ConnectionProvider connectionProvider = new HikariCPConnectionProvider(hikariConfigMap);

    String tableName = "wc";
    JdbcMapper simpleJdbcMapper = new SimpleJdbcMapper(tableName, connectionProvider);

    JdbcInsertBolt userPersistanceBolt = new JdbcInsertBolt(connectionProvider, simpleJdbcMapper)
            .withTableName(tableName)
            .withQueryTimeoutSecs(30);
    builder.setBolt("JdbcInsertBolt", userPersistanceBolt).shuffleGrouping("CountBolt");

    //创建本地集群
    LocalCluster cluster = new LocalCluster();
    cluster.submitTopology("LocalWordCountRedisStormTopology", new Config(), builder.createTopology());

}
 
Example 3
Source Project: streamline   Source File: StreamlineJdbcMapper.java    License: Apache License 2.0 5 votes vote down vote up
public StreamlineJdbcMapper(String tableName,
                            ConnectionProvider connectionProvider,
                            List<String> fields) {
    this.tableName = tableName;
    this.connectionProvider = connectionProvider;
    this.fields = fields;
    LOG.info("JDBC Mapper initialized with tableName: {}, connectionProvider: {}, fields: {}",
            tableName, connectionProvider, fields);
}
 
Example 4
Source Project: streamline   Source File: StreamlineJdbcInsertBolt.java    License: Apache License 2.0 4 votes vote down vote up
public StreamlineJdbcInsertBolt(ConnectionProvider connectionProvider, JdbcMapper jdbcMapper) {
    super(connectionProvider, jdbcMapper);
}