在拓扑主方法中设置 MessageTimeoutSecs 时在 JmsSpout 中获取 ClassCastException

get a ClassCastException inJmsSpout when setting MessageTimeoutSecs in topology main method

我在 topology main 方法中设置了 MessageTimeoutSecs 参数。

 Config conf = new Config();      
 conf.setMessageTimeoutSecs(200); //this is a int 
 StormSubmitter.submitTopology(args[0], conf, builder.createTopology());

但是我得到一个转换错误:

java.lang.ClassCastException: java.lang.Long cannot be cast to java.lang.Integer
at backtype.storm.contrib.jms.spout.JmsSpout.open(JmsSpout.java:160) ~[stormjar.jar:na]
at backtype.storm.daemon.executor$fn__6579$fn__6594.invoke(executor.clj:522) ~[storm-core-0.9.5.jar:0.9.5]
at backtype.storm.util$async_loop$fn__459.invoke(util.clj:461) ~[storm-core-0.9.5.jar:0.9.5]
at clojure.lang.AFn.run(AFn.java:24) [clojure-1.5.1.jar:na]
at java.lang.Thread.run(Thread.java:662) [na:1.6.0_22]

JmsSpout 代码是:

Integer topologyTimeout = (Integer)conf.get("topology.message.timeout.secs");
// TODO fine a way to get the default timeout from storm, so we're not hard-coding to 30 seconds (it could change)
topologyTimeout = topologyTimeout == null ? 30 : topologyTimeout;

有人知道为什么吗?

Storm 似乎在内部将超时值转换为 long。不知道为什么。要解决此问题,您需要转换为 Long(如果需要整数,则随后转换为 Integerint)。

Object timeout = conf.get("topology.message.timeout.secs");
Integer topologyTimeout = timeout == null ? 30 : ((Long)timeout).intValue;