當前位置: 首頁>>代碼示例>>Java>>正文


Java ZkUtils.zkClient方法代碼示例

本文整理匯總了Java中kafka.utils.ZkUtils.zkClient方法的典型用法代碼示例。如果您正苦於以下問題:Java ZkUtils.zkClient方法的具體用法?Java ZkUtils.zkClient怎麽用?Java ZkUtils.zkClient使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在kafka.utils.ZkUtils的用法示例。


在下文中一共展示了ZkUtils.zkClient方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: before

import kafka.utils.ZkUtils; //導入方法依賴的package包/類
@Before
public void before() {

    zkServer = new EmbeddedZookeeper();
    zkConnect = String.format("localhost:%d", zkServer.port());
    ZkUtils zkUtils = ZkUtils.apply(zkConnect, 30000, 30000,
            JaasUtils.isZkSecurityEnabled());
    zkClient = zkUtils.zkClient();

    final Option<java.io.File> noFile = scala.Option.apply(null);
    final Option<SecurityProtocol> noInterBrokerSecurityProtocol = scala.Option
            .apply(null);

    kafkaProps = TestUtils.createBrokerConfig(brokerId, zkConnect, false,
            false, port, noInterBrokerSecurityProtocol, noFile, true,
            false, TestUtils.RandomPort(), false, TestUtils.RandomPort(),
            false, TestUtils.RandomPort());

    kafkaProps.setProperty("auto.create.topics.enable", "true");
    kafkaProps.setProperty("num.partitions", "1");
    // We *must* override this to use the port we allocated (Kafka currently
    // allocates one port
    // that it always uses for ZK
    kafkaProps.setProperty("zookeeper.connect", this.zkConnect);
    kafkaProps.setProperty("host.name", "localhost");
    kafkaProps.setProperty("port", port + "");

    KafkaConfig config = new KafkaConfig(kafkaProps);
    Time mock = new MockTime();
    kafkaServer = TestUtils.createServer(config, mock);

    // create topic
    TopicCommand.TopicCommandOptions options = new TopicCommand.TopicCommandOptions(
            new String[]{"--create", "--topic", topic,
                    "--replication-factor", "1", "--partitions", "1"});

    TopicCommand.createTopic(zkUtils, options);

    List<KafkaServer> servers = new ArrayList<KafkaServer>();
    servers.add(kafkaServer);
    TestUtils.waitUntilMetadataIsPropagated(
            scala.collection.JavaConversions.asScalaBuffer(servers), topic,
            0, 5000);
}
 
開發者ID:DarkPhoenixs,項目名稱:message-queue-client-framework,代碼行數:45,代碼來源:SenderTest.java

示例2: setUp

import kafka.utils.ZkUtils; //導入方法依賴的package包/類
@Before
public void setUp() throws Exception {

    zkServer = new EmbeddedZookeeper();
    zkConnect = String.format("localhost:%d", zkServer.port());
    ZkUtils zkUtils = ZkUtils.apply(zkConnect, 30000, 30000,
            JaasUtils.isZkSecurityEnabled());
    zkClient = zkUtils.zkClient();

    final Option<File> noFile = Option.apply(null);
    final Option<SecurityProtocol> noInterBrokerSecurityProtocol = Option
            .apply(null);

    kafkaProps = TestUtils.createBrokerConfig(brokerId, zkConnect, false,
            false, port, noInterBrokerSecurityProtocol, noFile, true,
            false, TestUtils.RandomPort(), false, TestUtils.RandomPort(),
            false, TestUtils.RandomPort());

    kafkaProps.setProperty("auto.create.topics.enable", "true");
    kafkaProps.setProperty("num.partitions", "1");
    // We *must* override this to use the port we allocated (Kafka currently
    // allocates one port
    // that it always uses for ZK
    kafkaProps.setProperty("zookeeper.connect", this.zkConnect);

    KafkaConfig config = new KafkaConfig(kafkaProps);
    Time mock = new MockTime();
    kafkaServer = TestUtils.createServer(config, mock);

    // create topic
    TopicCommand.TopicCommandOptions options = new TopicCommand.TopicCommandOptions(
            new String[]{"--create", "--topic", topic,
                    "--replication-factor", "1", "--partitions", "2"});

    TopicCommand.createTopic(zkUtils, options);

    List<KafkaServer> servers = new ArrayList<KafkaServer>();
    servers.add(kafkaServer);
    TestUtils.waitUntilMetadataIsPropagated(
            scala.collection.JavaConversions.asScalaBuffer(servers), topic,
            0, 5000);
}
 
開發者ID:DarkPhoenixs,項目名稱:message-queue-client-framework,代碼行數:43,代碼來源:KafkaMessageNewReceiverPoolTest3.java

示例3: setUp

import kafka.utils.ZkUtils; //導入方法依賴的package包/類
@Before
public void setUp() throws Exception {

    zkServer = new EmbeddedZookeeper();
    zkConnect = String.format("localhost:%d", zkServer.port());
    ZkUtils zkUtils = ZkUtils.apply(zkConnect, 30000, 30000,
            JaasUtils.isZkSecurityEnabled());
    zkClient = zkUtils.zkClient();

    final Option<File> noFile = scala.Option.apply(null);
    final Option<SecurityProtocol> noInterBrokerSecurityProtocol = scala.Option
            .apply(null);

    kafkaProps = TestUtils.createBrokerConfig(brokerId, zkConnect, false,
            false, port, noInterBrokerSecurityProtocol, noFile, true,
            false, TestUtils.RandomPort(), false, TestUtils.RandomPort(),
            false, TestUtils.RandomPort());

    kafkaProps.setProperty("auto.create.topics.enable", "true");
    kafkaProps.setProperty("num.partitions", "1");
    // We *must* override this to use the port we allocated (Kafka currently
    // allocates one port
    // that it always uses for ZK
    kafkaProps.setProperty("zookeeper.connect", this.zkConnect);

    KafkaConfig config = new KafkaConfig(kafkaProps);
    Time mock = new MockTime();
    kafkaServer = TestUtils.createServer(config, mock);

    // create topic
    TopicCommand.TopicCommandOptions options = new TopicCommand.TopicCommandOptions(
            new String[]{"--create", "--topic", topic,
                    "--replication-factor", "1", "--partitions", "2"});

    TopicCommand.createTopic(zkUtils, options);

    List<KafkaServer> servers = new ArrayList<KafkaServer>();
    servers.add(kafkaServer);
    TestUtils.waitUntilMetadataIsPropagated(
            scala.collection.JavaConversions.asScalaBuffer(servers), topic,
            0, 5000);
}
 
開發者ID:DarkPhoenixs,項目名稱:message-queue-client-framework,代碼行數:43,代碼來源:KafkaMessageNewReceiverPoolTest.java

示例4: setUp

import kafka.utils.ZkUtils; //導入方法依賴的package包/類
@Before
public void setUp() throws Exception {

    zkServer = new EmbeddedZookeeper();
    zkConnect = String.format("localhost:%d", zkServer.port());
    ZkUtils zkUtils = ZkUtils.apply(zkConnect, 30000, 30000,
            JaasUtils.isZkSecurityEnabled());
    zkClient = zkUtils.zkClient();

    final Option<File> noFile = scala.Option.apply(null);
    final Option<SecurityProtocol> noInterBrokerSecurityProtocol = scala.Option
            .apply(null);

    kafkaProps = TestUtils.createBrokerConfig(brokerId, zkConnect, false,
            false, port, noInterBrokerSecurityProtocol, noFile, true,
            false, TestUtils.RandomPort(), false, TestUtils.RandomPort(),
            false, TestUtils.RandomPort());

    kafkaProps.setProperty("auto.create.topics.enable", "true");
    kafkaProps.setProperty("num.partitions", "1");
    // We *must* override this to use the port we allocated (Kafka currently
    // allocates one port
    // that it always uses for ZK
    kafkaProps.setProperty("zookeeper.connect", this.zkConnect);

    KafkaConfig config = new KafkaConfig(kafkaProps);
    Time mock = new MockTime();
    kafkaServer = TestUtils.createServer(config, mock);

    // create topic
    TopicCommand.TopicCommandOptions options = new TopicCommand.TopicCommandOptions(
            new String[]{"--create", "--topic", topic,
                    "--replication-factor", "1", "--partitions", "1"});

    TopicCommand.createTopic(zkUtils, options);

    List<KafkaServer> servers = new ArrayList<KafkaServer>();
    servers.add(kafkaServer);
    TestUtils.waitUntilMetadataIsPropagated(
            scala.collection.JavaConversions.asScalaBuffer(servers), topic,
            0, 5000);
}
 
開發者ID:DarkPhoenixs,項目名稱:message-queue-client-framework,代碼行數:43,代碼來源:KafkaMessageNewSenderPoolTest.java

示例5: before

import kafka.utils.ZkUtils; //導入方法依賴的package包/類
@Before
public void before() {

    zkServer = new EmbeddedZookeeper();
    zkConnect = String.format("localhost:%d", zkServer.port());
    ZkUtils zkUtils = ZkUtils.apply(zkConnect, 30000, 30000,
            JaasUtils.isZkSecurityEnabled());
    zkClient = zkUtils.zkClient();

    final Option<java.io.File> noFile = Option.apply(null);
    final Option<SecurityProtocol> noInterBrokerSecurityProtocol = Option
            .apply(null);

    kafkaProps = TestUtils.createBrokerConfig(brokerId, zkConnect, false,
            false, port, noInterBrokerSecurityProtocol, noFile, true,
            false, TestUtils.RandomPort(), false, TestUtils.RandomPort(),
            false, TestUtils.RandomPort());

    kafkaProps.setProperty("auto.create.topics.enable", "true");
    kafkaProps.setProperty("num.partitions", "1");
    // We *must* override this to use the port we allocated (Kafka currently
    // allocates one port
    // that it always uses for ZK
    kafkaProps.setProperty("zookeeper.connect", this.zkConnect);
    kafkaProps.setProperty("host.name", "localhost");
    kafkaProps.setProperty("port", port + "");

    KafkaConfig config = new KafkaConfig(kafkaProps);
    Time mock = new MockTime();
    kafkaServer = TestUtils.createServer(config, mock);

    // create topic
    TopicCommand.TopicCommandOptions options = new TopicCommand.TopicCommandOptions(
            new String[]{"--create", "--topic", topic,
                    "--replication-factor", "1", "--partitions", "1"});

    TopicCommand.createTopic(zkUtils, options);

    List<KafkaServer> servers = new ArrayList<KafkaServer>();
    servers.add(kafkaServer);
    TestUtils.waitUntilMetadataIsPropagated(
            scala.collection.JavaConversions.asScalaBuffer(servers), topic,
            0, 5000);
}
 
開發者ID:DarkPhoenixs,項目名稱:message-queue-client-framework,代碼行數:45,代碼來源:NewSenderWithSpringTest.java

示例6: before

import kafka.utils.ZkUtils; //導入方法依賴的package包/類
@Before
public void before() {

    zkServer = new EmbeddedZookeeper();
    zkConnect = String.format("localhost:%d", zkServer.port());
    ZkUtils zkUtils = ZkUtils.apply(zkConnect, 30000, 30000,
            JaasUtils.isZkSecurityEnabled());
    zkClient = zkUtils.zkClient();

    final Option<java.io.File> noFile = scala.Option.apply(null);
    final Option<SecurityProtocol> noInterBrokerSecurityProtocol = scala.Option
            .apply(null);

    port = TestUtils.RandomPort();
    kafkaProps = TestUtils.createBrokerConfig(brokerId, zkConnect, false,
            false, port, noInterBrokerSecurityProtocol, noFile, true,
            false, TestUtils.RandomPort(), false, TestUtils.RandomPort(),
            false, TestUtils.RandomPort());

    kafkaProps.setProperty("auto.create.topics.enable", "true");
    kafkaProps.setProperty("num.partitions", "1");
    // We *must* override this to use the port we allocated (Kafka currently
    // allocates one port
    // that it always uses for ZK
    kafkaProps.setProperty("zookeeper.connect", this.zkConnect);

    KafkaConfig config = new KafkaConfig(kafkaProps);
    Time mock = new MockTime();
    kafkaServer = TestUtils.createServer(config, mock);

    // create topic
    TopicCommand.TopicCommandOptions options = new TopicCommand.TopicCommandOptions(
            new String[]{"--create", "--topic", topic,
                    "--replication-factor", "1", "--partitions", "1"});

    TopicCommand.createTopic(zkUtils, options);

    List<KafkaServer> servers = new ArrayList<KafkaServer>();
    servers.add(kafkaServer);
    TestUtils.waitUntilMetadataIsPropagated(
            scala.collection.JavaConversions.asScalaBuffer(servers), topic,
            0, 5000);
}
 
開發者ID:DarkPhoenixs,項目名稱:message-queue-client-framework,代碼行數:44,代碼來源:KafkaCommandTest.java

示例7: setUp

import kafka.utils.ZkUtils; //導入方法依賴的package包/類
@Before
public void setUp() throws Exception {

    zkServer = new EmbeddedZookeeper();
    zkConnect = String.format("localhost:%d", zkServer.port());
    ZkUtils zkUtils = ZkUtils.apply(zkConnect, 30000, 30000,
            JaasUtils.isZkSecurityEnabled());
    zkClient = zkUtils.zkClient();

    final Option<File> noFile = scala.Option.apply(null);
    final Option<SecurityProtocol> noInterBrokerSecurityProtocol = scala.Option
            .apply(null);

    kafkaProps = TestUtils.createBrokerConfig(brokerId, zkConnect, false,
            false, port, noInterBrokerSecurityProtocol, noFile, true,
            false, TestUtils.RandomPort(), false, TestUtils.RandomPort(),
            false, TestUtils.RandomPort());

    kafkaProps.setProperty("auto.create.topics.enable", "true");
    kafkaProps.setProperty("num.partitions", "1");
    // We *must* override this to use the port we allocated (Kafka currently
    // allocates one port
    // that it always uses for ZK
    kafkaProps.setProperty("zookeeper.connect", this.zkConnect);

    KafkaConfig config = new KafkaConfig(kafkaProps);
    Time mock = new MockTime();
    kafkaServer = TestUtils.createServer(config, mock);

    // create topic
    TopicCommand.TopicCommandOptions options = new TopicCommand.TopicCommandOptions(
            new String[]{"--create", "--topic", topic,
                    "--replication-factor", "1", "--partitions", "4"});

    TopicCommand.createTopic(zkUtils, options);

    List<KafkaServer> servers = new ArrayList<KafkaServer>();
    servers.add(kafkaServer);
    TestUtils.waitUntilMetadataIsPropagated(
            scala.collection.JavaConversions.asScalaBuffer(servers), topic,
            0, 5000);
}
 
開發者ID:DarkPhoenixs,項目名稱:message-queue-client-framework,代碼行數:43,代碼來源:KafkaMessageNewSenderTest.java

示例8: before

import kafka.utils.ZkUtils; //導入方法依賴的package包/類
@Before
public void before() {

    zkServer = new EmbeddedZookeeper();
    zkConnect = String.format("localhost:%d", zkServer.port());
    ZkUtils zkUtils = ZkUtils.apply(zkConnect, 30000, 30000,
            JaasUtils.isZkSecurityEnabled());
    zkClient = zkUtils.zkClient();

    final Option<java.io.File> noFile = scala.Option.apply(null);
    final Option<SecurityProtocol> noInterBrokerSecurityProtocol = scala.Option
            .apply(null);

    kafkaProps = TestUtils.createBrokerConfig(brokerId, zkConnect, false,
            false, port, noInterBrokerSecurityProtocol, noFile, true,
            false, TestUtils.RandomPort(), false, TestUtils.RandomPort(),
            false, TestUtils.RandomPort());

    kafkaProps.setProperty("auto.create.topics.enable", "true");
    kafkaProps.setProperty("num.partitions", "1");
    // We *must* override this to use the port we allocated (Kafka currently
    // allocates one port
    // that it always uses for ZK
    kafkaProps.setProperty("zookeeper.connect", this.zkConnect);
    kafkaProps.setProperty("host.name", "localhost");
    kafkaProps.setProperty("port", port + "");

    KafkaConfig config = new KafkaConfig(kafkaProps);
    Time mock = new MockTime();
    kafkaServer = TestUtils.createServer(config, mock);

    // create topic
    TopicCommand.TopicCommandOptions options = new TopicCommand.TopicCommandOptions(
            new String[]{"--create", "--topic", topic,
                    "--replication-factor", "1", "--partitions", "4"});

    TopicCommand.createTopic(zkUtils, options);

    List<KafkaServer> servers = new ArrayList<KafkaServer>();
    servers.add(kafkaServer);
    TestUtils.waitUntilMetadataIsPropagated(
            scala.collection.JavaConversions.asScalaBuffer(servers), topic,
            0, 5000);
}
 
開發者ID:DarkPhoenixs,項目名稱:message-queue-client-framework,代碼行數:45,代碼來源:ZookeeperBrokersTest.java

示例9: before

import kafka.utils.ZkUtils; //導入方法依賴的package包/類
@Before
public void before() {

    zkServer = new EmbeddedZookeeper();
    zkConnect = String.format("localhost:%d", zkServer.port());
    ZkUtils zkUtils = ZkUtils.apply(zkConnect, 30000, 30000,
            JaasUtils.isZkSecurityEnabled());
    zkClient = zkUtils.zkClient();

    final Option<java.io.File> noFile = scala.Option.apply(null);
    final Option<SecurityProtocol> noInterBrokerSecurityProtocol = scala.Option
            .apply(null);

    kafkaProps = TestUtils.createBrokerConfig(brokerId, zkConnect, false,
            false, port, noInterBrokerSecurityProtocol, noFile, true,
            false, TestUtils.RandomPort(), false, TestUtils.RandomPort(),
            false, TestUtils.RandomPort());

    kafkaProps.setProperty("auto.create.topics.enable", "true");
    kafkaProps.setProperty("num.partitions", "1");
    // We *must* override this to use the port we allocated (Kafka currently
    // allocates one port
    // that it always uses for ZK
    kafkaProps.setProperty("zookeeper.connect", this.zkConnect);
    kafkaProps.setProperty("host.name", "localhost");
    kafkaProps.setProperty("port", port + "");

    Properties kafkaProps2 = TestUtils.createBrokerConfig(brokerId + 1,
            zkConnect, false, false, (port - 1),
            noInterBrokerSecurityProtocol, noFile, true, false,
            TestUtils.RandomPort(), false, TestUtils.RandomPort(), false,
            TestUtils.RandomPort());

    kafkaProps2.setProperty("auto.create.topics.enable", "true");
    kafkaProps2.setProperty("num.partitions", "1");
    // We *must* override this to use the port we allocated (Kafka currently
    // allocates one port
    // that it always uses for ZK
    kafkaProps2.setProperty("zookeeper.connect", this.zkConnect);
    kafkaProps2.setProperty("host.name", "localhost");
    kafkaProps2.setProperty("port", (port - 1) + "");

    KafkaConfig config = new KafkaConfig(kafkaProps);
    KafkaConfig config2 = new KafkaConfig(kafkaProps2);

    Time mock = new MockTime();
    Time mock2 = new MockTime();

    kafkaServer = TestUtils.createServer(config, mock);
    KafkaServer kafkaServer2 = TestUtils.createServer(config2, mock2);

    // create topic
    TopicCommand.TopicCommandOptions options = new TopicCommand.TopicCommandOptions(
            new String[]{"--create", "--topic", topic,
                    "--replication-factor", "2", "--partitions", "2"});

    TopicCommand.createTopic(zkUtils, options);

    List<KafkaServer> servers = new ArrayList<KafkaServer>();
    servers.add(kafkaServer);
    servers.add(kafkaServer2);
    TestUtils.waitUntilMetadataIsPropagated(
            scala.collection.JavaConversions.asScalaBuffer(servers), topic,
            0, 5000);
}
 
開發者ID:DarkPhoenixs,項目名稱:message-queue-client-framework,代碼行數:66,代碼來源:KafkaMessageReceiverImplTest.java


注:本文中的kafka.utils.ZkUtils.zkClient方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。