storm创建DRPC远程客户端

创建DRPC远程客户端

DRPCClient创建方法如下:

1
2
//conf map, drpc server, port no, timeout for the call
new DRPCClient(conf, "192.168.0.217", 3772, 5000);

conf如下:

1
2
Config conf = new Config();
conf.setDebug(false);

这将产生下列这个错误:

1
2
3
4
java.lang.NullPointerException
java.lang.RuntimeException: java.lang.NullPointerException
at backtype.storm.security.auth.AuthUtils.GetTransportPlugin(AuthUtils.java:230)
at backtype.storm.security.auth.ThriftClient.reconnect(ThriftClient.java:91)

如何添加下列这句话:

1
conf.put("storm.thrift.transport", "backtype.storm.security.auth.SimpleTransportPlugin");

这将继续报这个错误:

1
2
3
4
Don't know how to convert null to int
java.lang.IllegalArgumentException: Don't know how to convert null to int
at backtype.storm.utils.Utils.getInt(Utils.java:420)
at backtype.storm.security.auth.ThriftClient.reconnect(ThriftClient.java:100)

在storm0.10之后就已经做了改进,使用map来传递配置参数。

正确做法:

1
2
3
4
5
6
7
8
9
10
11
12
Config conf = new Config();
Map defaultConfig = Utils.readDefaultConfig();

defaultConfig.put("storm.thrift.transport","org.apache.storm.security.auth.SimpleTransportPlugin");
defaultConfig.put(Config.STORM_EXHIBITOR_RETRY_TIMES, 3);
defaultConfig.put(Config.STORM_EXHIBITOR_RETRY_INTERVAL, 10);
defaultConfig.put(Config.STORM_EXHIBITOR_RETRY_INTERVAL_CEILING, 20);
defaultConfig.put(Config.DRPC_MAX_BUFFER_SIZE, 1048576);

conf.putAll(defaultConfig);

DRPCClient drpcClient = new DRPCClient(conf,"localhost", 3772,5000);