本文介绍了是否有可能在过程中启动一个zookeeper服务器实例,比如单元测试?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

调用org.apache.zookeeper.server.quorum.QuorumPeerMain.main()不起作用。 开始 ZooKeeper 您必须执行 ZooKeeperServerMain class。



您可以使用以下代码在嵌入模式下启动 ZooKeeper

 属性startupProperties = ... 

QuorumPeerConfig quorumConfiguration = new QuorumPeerConfig();
尝试{
quorumConfiguration.parseProperties(startupProperties);
} catch(Exception e){
throw new RuntimeException(e);
}

zooKeeperServer = new ZooKeeperServerMain();
最终ServerConfig配置=新ServerConfig();
configuration.readFrom(quorumConfiguration);
$ b $ new Thread(){
public void run(){
try {
zooKeeperServer.runFromConfig(configuration);
} catch(IOException e){
log.error(ZooKeeper Failed,e);
}
}
} .start();


calling org.apache.zookeeper.server.quorum.QuorumPeerMain.main() isn't working.

解决方案

To start ZooKeeper you have to execute ZooKeeperServerMain class.

You can use following code to start ZooKeeper in embedded mode.

Properties startupProperties = ...

QuorumPeerConfig quorumConfiguration = new QuorumPeerConfig();
try {
    quorumConfiguration.parseProperties(startupProperties);
} catch(Exception e) {
    throw new RuntimeException(e);
}

zooKeeperServer = new ZooKeeperServerMain();
final ServerConfig configuration = new ServerConfig();
configuration.readFrom(quorumConfiguration);

new Thread() {
    public void run() {
        try {
            zooKeeperServer.runFromConfig(configuration);
        } catch (IOException e) {
            log.error("ZooKeeper Failed", e);
        }
    }
}.start();

这篇关于是否有可能在过程中启动一个zookeeper服务器实例,比如单元测试?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-11 08:09