我想实例化一个LocalCluster()并阻止它运行自己的嵌入式zookeeper,而是使用我的。
关于此问题:“https://issues.apache.org/jira/browse/STORM-213”已针对0.9.3版解析。
我可以为此提供示例代码吗?
PS:我正在集成测试我的风暴拓扑,我使用kafka和zookeeper作为风暴的输入。 当我没有将zookeeper信息指定给localcluster时,我在“LocalCluster localCluster = new LocalCluster()”行中得到此异常:
2016-06-08 12:16:56,785 WARN [Thread-30] jmx.MBeanRegistry (MBeanRegistry.java:register(100)) - Failed to register MBean StandaloneServer_port-1
2016-06-08 12:16:56,785 WARN [Thread-30] server.ZooKeeperServer (ZooKeeperServer.java:registerJMX(387)) - Failed to register with JMX
javax.management.InstanceAlreadyExistsException: org.apache.ZooKeeperService:name0=StandaloneServer_port-1
at com.sun.jmx.mbeanserver.Repository.addMBean(Repository.java:437)
at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.registerWithRepository(DefaultMBeanServerInterceptor.java:1898)
at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.registerDynamicMBean(DefaultMBeanServerInterceptor.java:966)
at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.registerObject(DefaultMBeanServerInterceptor.java:900)
at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.registerMBean(DefaultMBeanServerInterceptor.java:324)
at com.sun.jmx.mbeanserver.JmxMBeanServer.registerMBean(JmxMBeanServer.java:522)
at org.apache.zookeeper.jmx.MBeanRegistry.register(MBeanRegistry.java:96)
at org.apache.zookeeper.server.ZooKeeperServer.registerJMX(ZooKeeperServer.java:377)
at org.apache.zookeeper.server.ZooKeeperServer.startup(ZooKeeperServer.java:410)
at org.apache.zookeeper.server.NIOServerCnxnFactory.startup(NIOServerCnxnFactory.java:123)
当我将“storm.zookeeper.servers”和“storm.zookeeper.port”指定给本地群集时,我在“localCluster.submitTopology()”行中得到以下异常:
EndOfStreamException: Unable to read additional data from client sessionid 0x1552f0890b70000, likely client has closed socket
at org.apache.zookeeper.server.NIOServerCnxn.doIO(NIOServerCnxn.java:228)
at org.apache.zookeeper.server.NIOServerCnxnFactory.run(NIOServerCnxnFactory.java:208)
at java.lang.Thread.run(Thread.java:745)
java.lang.NullPointerException
at clojure.lang.Reflector.invokeInstanceMethod(Reflector.java:26)
at org.apache.storm.testing$submit_local_topology.invoke(testing.clj:301)
at org.apache.storm.LocalCluster$_submitTopology.invoke(LocalCluster.clj:49)
at org.apache.storm.LocalCluster.submitTopology(Unknown Source)
答案 0 :(得分:0)
您可以使用重载LocalCluster
构造函数。
LocalCluster cluster = new LocalCluster("localhost", 2181L);
答案 1 :(得分:0)
我可以使用此链接提供的配置http://storm.apache.org/releases/1.0.2/storm-kafka.html
将Kafka用作Storm拓扑的输入我为storm配置创建了一个特定的java类
public class StormConfig {
private String zooKeeperConnect;
public StormConfig() {
}
public KafkaSpout getkafkaSpout(String topic){
return new KafkaSpout(this.getSpoutConfig(topic));
}
public SpoutConfig getSpoutConfig(String topic) {
SpoutConfig spoutConfig=new SpoutConfig(this.getZkHosts(), topic, "", topic);
spoutConfig.scheme = new SchemeAsMultiScheme(new StringScheme());
spoutConfig.startOffsetTime=kafka.api.OffsetRequest.EarliestTime();
return spoutConfig;
}
public ZkHosts getZkHosts() {
return new ZkHosts(getZooKeeperConnect());
}
public String getZooKeeperConnect() {
return zooKeeperConnect;
}
public void setZooKeeperConnect(String zooKeeperConnect) {
this.zooKeeperConnect = zooKeeperConnect;
}
}
然后在创建拓扑的初始spout时使用了此类中的方法:
builder.setSpout("kafkaSpoutName", stormConfig.getkafkaSpout("topicName"))
.setNumTasks(Constants.SPOUT_NUM_TASKS);