我正在使用Maven创建一个Storm项目,其中我使用HikariCP连接(版本:2.7.3)连接了一个本地postgresql数据库,但它不起作用。 postgresql数据库是使用pgAdmin III和PostgreSQL 9.5创建的。 我正在使用1.1.1风暴版。
运行java项目中的相同代码。
package storm.topologies;
import org.apache.storm.jdbc.common.Column;
import org.apache.storm.jdbc.common.ConnectionProvider;
import org.apache.storm.jdbc.common.HikariCPConnectionProvider;
import org.apache.storm.jdbc.common.JdbcClient;
import org.apache.storm.jdbc.mapper.JdbcMapper;
import org.apache.storm.jdbc.mapper.JdbcLookupMapper;
import org.apache.storm.jdbc.mapper.SimpleJdbcMapper;
import org.apache.storm.jdbc.mapper.SimpleJdbcLookupMapper;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import itd.meter.storm.spouts.UserQueueSpout;
import java.sql.Types;
import java.util.List;
import java.util.Map;
import org.apache.storm.Config;
import org.apache.storm.LocalCluster;
import org.apache.storm.StormSubmitter;
import org.apache.storm.generated.StormTopology;
import org.apache.storm.tuple.Fields;
public abstract class AbstractUserTopology {
private static final List<String> setupSqls = Lists.newArrayList(
"create table if not exists table(x varchar(20), y varchar(20), id varchar(50))"
);
protected UserQueueSpout userQueueSpout;
protected JdbcMapper jdbcMapper;
protected JdbcLookupMapper jdbcLookupMapper;
protected ConnectionProvider connectionProvider;
protected static final String TABLE_NAME = "table";
protected static final String JDBC_CONF = "jdbc.conf";
String SELECT_QUERY ="select x,y from table where id ='01'";
public void execute(String[] args) throws Exception {
Map hikariConfigMap = Maps.newHashMap();
hikariConfigMap.put("jdbcUrl","jdbc:postgresql://127.0.0.1:5432/MYDB");
hikariConfigMap.put("dataSource.user", "postgres");
hikariConfigMap.put("dataSource.password", "password");
hikariConfigMap.put("dataSource.portNumber", "5432");
if (args.length == 4) {
hikariConfigMap.put("dataSource.password", args[3]);//password
}
Config config = new Config();
config.put(JDBC_CONF, hikariConfigMap);
ConnectionProvider connectionProvider = new HikariCPConnectionProvider(hikariConfigMap);
connectionProvider.prepare();
//query timeout seconds param that specifies
//max seconds an insert query can take
int queryTimeoutSecs = 60;
JdbcClient jdbcClient = new JdbcClient(connectionProvider, queryTimeoutSecs);
for (String sql : setupSqls) {
jdbcClient.executeSql(sql);
}
this.userQueueSpout = new UserQueueSpout();
this.jdbcMapper = new SimpleJdbcMapper(TABLE_NAME, connectionProvider);
connectionProvider.cleanup();
Fields outputFields = new Fields("x", "y","id");
List<Column> queryParamColumns = Lists.newArrayList(new Column("x", Types.VARCHAR), new Column("y", Types.VARCHAR), new Column("id",Types.VARCHAR));
this.jdbcLookupMapper = new SimpleJdbcLookupMapper(outputFields, queryParamColumns);
this.connectionProvider = new HikariCPConnectionProvider(hikariConfigMap);
if (args.length == 4) {
config.setDebug(false);
LocalCluster cluster = new LocalCluster();
cluster.submitTopology("stormProject", config, getTopology());
} else {
StormSubmitter.submitTopology(args[4], config, getTopology());
}
}
public abstract StormTopology getTopology();
}
错误下方:
56999 [storm.topologies.TOPOLOGY.main()] INFO o.a.s.j.c.HikariCPConnectionProvider - JDBC Url: jdbc:postgresql://127.0.0.1:5432/MYDB
57014 [storm.topologies.TOPOLOGY.main()] INFO c.z.h.HikariDataSource - HikariPool-1 - Starting...
57443 [storm.topologies.TOPOLOGY.main()] INFO c.z.h.p.PoolBase - HikariPool-1 - Driver does not support get/set network timeout for connections. (Il metodo ½org.postgresql.jdbc.PgConnection.getNetworkTimeout()╗ non Þ stato ancora implementato.)
57474 [storm.topologies.TOPOLOGY.main()] INFO c.z.h.HikariDataSource - HikariPool-1 - Start completed.
57528 [storm.topologies.TOPOLOGY.main()] INFO c.z.h.HikariDataSource - HikariPool-1 - Shutdown initiated...
57543 [storm.topologies.TOPOLOGY.main()] INFO c.z.h.HikariDataSource - HikariPool-1 - Shutdown completed.
[WARNING]
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.codehaus.mojo.exec.ExecJavaMojo$1.run(ExecJavaMojo.java:297)
at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.ArrayIndexOutOfBoundsException: 4
如何解决?