当前位置: 首页>>代码示例>>Java>>正文


Java ZkConnection类代码示例

本文整理汇总了Java中org.I0Itec.zkclient.ZkConnection的典型用法代码示例。如果您正苦于以下问题:Java ZkConnection类的具体用法?Java ZkConnection怎么用?Java ZkConnection使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ZkConnection类属于org.I0Itec.zkclient包,在下文中一共展示了ZkConnection类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createTopic

import org.I0Itec.zkclient.ZkConnection; //导入依赖的package包/类
/**
 * Create a Kafka topic with the given parameters.
 *
 * @param topic       The name of the topic.
 * @param partitions  The number of partitions for this topic.
 * @param replication The replication factor for (partitions of) this topic.
 * @param topicConfig Additional topic-level configuration settings.
 */
public void createTopic(final String topic,
                        final int partitions,
                        final int replication,
                        final Properties topicConfig) {
    log.debug("Creating topic { name: {}, partitions: {}, replication: {}, config: {} }",
        topic, partitions, replication, topicConfig);

    // Note: You must initialize the ZkClient with ZKStringSerializer.  If you don't, then
    // createTopic() will only seem to work (it will return without error).  The topic will exist in
    // only ZooKeeper and will be returned when listing topics, but Kafka itself does not create the
    // topic.
    final ZkClient zkClient = new ZkClient(
        zookeeperConnect(),
        DEFAULT_ZK_SESSION_TIMEOUT_MS,
        DEFAULT_ZK_CONNECTION_TIMEOUT_MS,
        ZKStringSerializer$.MODULE$);
    final boolean isSecure = false;
    final ZkUtils zkUtils = new ZkUtils(zkClient, new ZkConnection(zookeeperConnect()), isSecure);
    AdminUtils.createTopic(zkUtils, topic, partitions, replication, topicConfig, RackAwareMode.Enforced$.MODULE$);
    zkClient.close();
}
 
开发者ID:YMCoding,项目名称:kafka-0.11.0.0-src-with-comment,代码行数:30,代码来源:KafkaEmbedded.java

示例2: createTopic

import org.I0Itec.zkclient.ZkConnection; //导入依赖的package包/类
/**
 * Create a Kafka topic with the given parameters.
 *
 * @param topic       The name of the topic.
 * @param partitions  The number of partitions for this topic.
 * @param replication The replication factor for (partitions of) this topic.
 * @param topicConfig Additional topic-level configuration settings.
 */
public void createTopic(String topic,
                        int partitions,
                        int replication,
                        Properties topicConfig) {
  log.debug("Creating topic { name: {}, partitions: {}, replication: {}, config: {} }",
      topic, partitions, replication, topicConfig);
  // Note: You must initialize the ZkClient with ZKStringSerializer.  If you don't, then
  // createTopic() will only seem to work (it will return without error).  The topic will exist in
  // only ZooKeeper and will be returned when listing topics, but Kafka itself does not create the
  // topic.
  ZkClient zkClient = new ZkClient(
      zookeeperConnect(),
      DEFAULT_ZK_SESSION_TIMEOUT_MS,
      DEFAULT_ZK_CONNECTION_TIMEOUT_MS,
      ZKStringSerializer$.MODULE$);
  boolean isSecure = false;
  ZkUtils zkUtils = new ZkUtils(zkClient, new ZkConnection(zookeeperConnect()), isSecure);
  AdminUtils.createTopic(zkUtils, topic, partitions, replication, topicConfig, RackAwareMode.Enforced$.MODULE$);
  zkClient.close();
}
 
开发者ID:kaiwaehner,项目名称:kafka-streams-machine-learning-examples,代码行数:29,代码来源:KafkaEmbedded.java

示例3: createTopic

import org.I0Itec.zkclient.ZkConnection; //导入依赖的package包/类
/**
 * Create a Kafka topic with the given parameters.
 *
 * @param topic       The name of the topic.
 * @param partitions  The number of partitions for this topic.
 * @param replication The replication factor for (partitions of) this topic.
 * @param topicConfig Additional topic-level configuration settings.
 */
public void createTopic(final String topic,
                        final int partitions,
                        final int replication,
                        final Properties topicConfig) {
  log.debug("Creating topic { name: {}, partitions: {}, replication: {}, config: {} }",
      topic, partitions, replication, topicConfig);

  // Note: You must initialize the ZkClient with ZKStringSerializer.  If you don't, then
  // createTopic() will only seem to work (it will return without error).  The topic will exist in
  // only ZooKeeper and will be returned when listing topics, but Kafka itself does not create the
  // topic.
  final ZkClient zkClient = new ZkClient(
      zookeeperConnect(),
      DEFAULT_ZK_SESSION_TIMEOUT_MS,
      DEFAULT_ZK_CONNECTION_TIMEOUT_MS,
      ZKStringSerializer$.MODULE$);
  final boolean isSecure = false;
  final ZkUtils zkUtils = new ZkUtils(zkClient, new ZkConnection(zookeeperConnect()), isSecure);
  AdminUtils.createTopic(zkUtils, topic, partitions, replication, topicConfig, RackAwareMode.Enforced$.MODULE$);
  zkClient.close();
}
 
开发者ID:Landoop,项目名称:kafka-testkit,代码行数:30,代码来源:KafkaEmbedded.java

示例4: KafkaAdminClient

import org.I0Itec.zkclient.ZkConnection; //导入依赖的package包/类
/**
 * Creates and connects a new KafkaAdminClient
 * @param zkConnect The zk connect string
 * @param sessionTimeout The session timeout
 * @param connectionTimeout The connection timeout
 */
private KafkaAdminClient(final String zkConnect, final int sessionTimeout, final int connectionTimeout) {
	this.zkConnect = zkConnect;
	this.sessionTimeout = sessionTimeout;
	this.connectionTimeout = connectionTimeout;
	zkClient = new ZkClient(
			zkConnect,
			this.sessionTimeout,
			this.connectionTimeout,
		    ZKStringSerializer$.MODULE$);
	zkConnection = new ZkConnection(zkConnect, DEFAULT_SESSION_TIMEOUT);
	zkConnection.connect(this);
	zkUtils = new ZkUtils(zkClient, zkConnection, false);
	final String endPoint = findEndpoint(zkConnection);
	adminClient = endPoint==null ? null : AdminClient.createSimplePlaintext(endPoint);
	
}
 
开发者ID:nickman,项目名称:HeliosStreams,代码行数:23,代码来源:KafkaAdminClient.java

示例5: startKafka

import org.I0Itec.zkclient.ZkConnection; //导入依赖的package包/类
private void startKafka() throws Exception
{
  FileUtils.deleteDirectory(new File(kafkaTmpDir));

  Properties props = new Properties();
  props.setProperty("zookeeper.session.timeout.ms", "100000");
  props.put("advertised.host.name", "localhost");
  props.put("port", 11111);
  // props.put("broker.id", "0");
  props.put("log.dir", kafkaTmpDir);
  props.put("enable.zookeeper", "true");
  props.put("zookeeper.connect", zookeeperLocalCluster.getConnectString());
  KafkaConfig kafkaConfig = KafkaConfig.fromProps(props);
  kafkaLocalBroker = new KafkaServer(kafkaConfig, new SystemTime(), scala.Option.apply("kafkaThread"));
  kafkaLocalBroker.startup();

  zkClient = new ZkClient(zookeeperLocalCluster.getConnectString(), 60000, 60000, ZKStringSerializer$.MODULE$);
  ZkUtils zkUtils = new ZkUtils(zkClient, new ZkConnection(zookeeperLocalCluster.getConnectString()), false);
  // ZkUtils zkUtils = ZkUtils.apply(zookeeperLocalCluster.getConnectString(), 60000, 60000, false);
  AdminUtils.createTopic(zkUtils, topic, 1, 1, new Properties());
}
 
开发者ID:apache,项目名称:incubator-pirk,代码行数:22,代码来源:KafkaStormIntegrationTest.java

示例6: initKafka

import org.I0Itec.zkclient.ZkConnection; //导入依赖的package包/类
@BeforeClass
public static void initKafka() throws Exception {
  synchronized (TestKafkaSuit.class) {
    if (initCount.get() == 0) {
      ZookeeperTestUtil.setZookeeperSaslTestConfigProps();
      System.setProperty(JaasUtils.JAVA_LOGIN_CONFIG_PARAM, ClassLoader.getSystemResource(LOGIN_CONF_RESOURCE_PATHNAME).getFile());
      embeddedKafkaCluster = new EmbeddedKafkaCluster();
      Properties topicProps = new Properties();
      zkClient = new ZkClient(embeddedKafkaCluster.getZkServer().getConnectionString(), SESSION_TIMEOUT, CONN_TIMEOUT, ZKStringSerializer$.MODULE$);
      ZkUtils zkUtils = new ZkUtils(zkClient, new ZkConnection(embeddedKafkaCluster.getZkServer().getConnectionString()), false);
      AdminUtils.createTopic(zkUtils, QueryConstants.JSON_TOPIC, 1, 1, topicProps, RackAwareMode.Disabled$.MODULE$);

      org.apache.kafka.common.requests.MetadataResponse.TopicMetadata fetchTopicMetadataFromZk = AdminUtils
          .fetchTopicMetadataFromZk(QueryConstants.JSON_TOPIC, zkUtils);
      logger.info("Topic Metadata: " + fetchTopicMetadataFromZk);

      KafkaMessageGenerator generator = new KafkaMessageGenerator(embeddedKafkaCluster.getKafkaBrokerList(),
          StringSerializer.class);
      generator.populateJsonMsgIntoKafka(QueryConstants.JSON_TOPIC, NUM_JSON_MSG);
    }
    initCount.incrementAndGet();
    runningSuite = true;
  }
  logger.info("Initialized Embedded Zookeeper and Kafka");
}
 
开发者ID:axbaretto,项目名称:drill,代码行数:26,代码来源:TestKafkaSuit.java

示例7: createTopic

import org.I0Itec.zkclient.ZkConnection; //导入依赖的package包/类
/**
 * Create a Kafka topic with the given parameters.
 *
 * @param topic       The name of the topic.
 * @param partitions  The number of partitions for this topic.
 * @param replication The replication factor for (partitions of) this topic.
 * @param topicConfig Additional topic-level configuration settings.
 */
public void createTopic(String topic,
                        int partitions,
                        int replication,
                        Properties topicConfig) {
  log.debug("Creating topic { name: {}, partitions: {}, replication: {}, config: {} }",
      topic, partitions, replication, topicConfig);
  // Note: You must initialize the ZkClient with ZKStringSerializer.  If you don't, then
  // registerTopic() will only seem to work (it will return without error).  The topic will exist in
  // only ZooKeeper and will be returned when listing topics, but Kafka itself does not create the
  // topic.
  ZkClient zkClient = new ZkClient(
      zookeeperConnect(),
      DEFAULT_ZK_SESSION_TIMEOUT_MS,
      DEFAULT_ZK_CONNECTION_TIMEOUT_MS,
      ZKStringSerializer$.MODULE$);
  boolean isSecure = false;
  ZkUtils zkUtils = new ZkUtils(zkClient, new ZkConnection(zookeeperConnect()), isSecure);
  AdminUtils.createTopic(zkUtils, topic, partitions, replication, topicConfig, RackAwareMode.Enforced$.MODULE$);
  zkClient.close();
}
 
开发者ID:confluentinc,项目名称:ksql,代码行数:29,代码来源:KafkaEmbedded.java

示例8: waitUntilConnected

import org.I0Itec.zkclient.ZkConnection; //导入依赖的package包/类
/**
 * wait until we get a non-zero session-id. note that we might lose zkconnection
 * right after we read session-id. but it's ok to get stale session-id and we will have
 * another handle-new-session callback to correct this.
 */
void waitUntilConnected() {
  boolean isConnected;
  do {
    isConnected =
        _zkclient.waitUntilConnected(ZkClient.DEFAULT_CONNECTION_TIMEOUT, TimeUnit.MILLISECONDS);
    if (!isConnected) {
      LOG.error("fail to connect zkserver: " + _zkAddress + " in "
          + ZkClient.DEFAULT_CONNECTION_TIMEOUT + "ms. expiredSessionId: " + _sessionId
          + ", clusterName: " + _clusterName);
      continue;
    }

    ZkConnection zkConnection = ((ZkConnection) _zkclient.getConnection());
    _sessionId = Long.toHexString(zkConnection.getZookeeper().getSessionId());

    /**
     * at the time we read session-id, zkconnection might be lost again
     * wait until we get a non-zero session-id
     */
  } while (!isConnected || "0".equals(_sessionId));

  LOG.info("Handling new session, session id: " + _sessionId + ", instance: " + _instanceName
      + ", instanceTye: " + _instanceType + ", cluster: " + _clusterName + ", zkconnection: "
      + ((ZkConnection) _zkclient.getConnection()).getZookeeper());
}
 
开发者ID:apache,项目名称:helix,代码行数:31,代码来源:ZKHelixManager.java

示例9: simulateSessionExpiry

import org.I0Itec.zkclient.ZkConnection; //导入依赖的package包/类
protected void simulateSessionExpiry(ZkConnection zkConnection) throws IOException,
    InterruptedException {
  ZooKeeper oldZookeeper = zkConnection.getZookeeper();
  LOG.info("Old sessionId = " + oldZookeeper.getSessionId());

  Watcher watcher = new Watcher() {
    @Override
    public void process(WatchedEvent event) {
      LOG.info("In New connection, process event:" + event);
    }
  };

  ZooKeeper newZookeeper =
      new ZooKeeper(zkConnection.getServers(), oldZookeeper.getSessionTimeout(), watcher,
          oldZookeeper.getSessionId(), oldZookeeper.getSessionPasswd());
  LOG.info("New sessionId = " + newZookeeper.getSessionId());
  // Thread.sleep(3000);
  newZookeeper.close();
  Thread.sleep(10000);
  oldZookeeper = zkConnection.getZookeeper();
  LOG.info("After session expiry sessionId = " + oldZookeeper.getSessionId());
}
 
开发者ID:apache,项目名称:helix,代码行数:23,代码来源:ZkUnitTestBase.java

示例10: createTopic

import org.I0Itec.zkclient.ZkConnection; //导入依赖的package包/类
public void createTopic(String topic) {
    ZkClient zkClient = new ZkClient(
            kafkaRpcConfig.getZookeeperConnect(),
            kafkaRpcConfig.getSessionTimeout(),
            kafkaRpcConfig.getConnectionTimeout(),
            ZKStringSerializer$.MODULE$);
    try {
        ZkUtils zkUtils = new ZkUtils(zkClient, new ZkConnection(kafkaRpcConfig.getZookeeperConnect()), false);
        Properties topicConfig = kafkaRpcConfig.topicProps();
        if (!AdminUtils.topicExists(zkUtils, topic)) {
            AdminUtils.createTopic(zkUtils, topic, kafkaRpcConfig.getNumPartitions(), 
                    kafkaRpcConfig.getReplicationFactor(), topicConfig, RackAwareMode.Enforced$.MODULE$);
        }
    } finally {
        zkClient.close();
    }
}
 
开发者ID:devicehive,项目名称:devicehive-java-server,代码行数:18,代码来源:KafkaRpcTopicService.java

示例11: getZKUtils

import org.I0Itec.zkclient.ZkConnection; //导入依赖的package包/类
/**
 * Create a Kafka Zookeeper client
 *
 * @param zkClient zookeeper client
 * @param zkServers It's a comma-separated list of zookeeper servers host:port
 * @return {@link ZkUtils} Kafka Zookeeper client
 * @throws com.mcafee.dxl.streaming.operations.client.exception.ConnectionException when Zookeeper connection failed
 */
protected ZkUtils getZKUtils(final ZkClient zkClient, final String zkServers) {
    try {
        return new ZkUtils(zkClient,
                new ZkConnection(zkServers),
                false);
    } catch (Exception e) {
        throw new ConnectionException(zkServers,e.getMessage(),e,this.getClass());
    }
}
 
开发者ID:mcafee,项目名称:management-sdk-for-kafka,代码行数:18,代码来源:ClusterConnection.java

示例12: BrokerFailureDetector

import org.I0Itec.zkclient.ZkConnection; //导入依赖的package包/类
public BrokerFailureDetector(KafkaCruiseControlConfig config,
                             LoadMonitor loadMonitor,
                             Queue<Anomaly> anomalies,
                             Time time) {
  String zkUrl = config.getString(KafkaCruiseControlConfig.ZOOKEEPER_CONNECT_CONFIG);
  ZkConnection zkConnection = new ZkConnection(zkUrl, 30000);
  _zkClient = new ZkClient(zkConnection, 30000, new ZkStringSerializer());
  // Do not support secure ZK at this point.
  _zkUtils = new ZkUtils(_zkClient, zkConnection, false);
  _failedBrokers = new HashMap<>();
  _failedBrokersZkPath = config.getString(KafkaCruiseControlConfig.FAILED_BROKERS_ZK_PATH_CONFIG);
  _loadMonitor = loadMonitor;
  _anomalies = anomalies;
  _time = time;
}
 
开发者ID:linkedin,项目名称:cruise-control,代码行数:16,代码来源:BrokerFailureDetector.java

示例13: checkAndCreateTopic

import org.I0Itec.zkclient.ZkConnection; //导入依赖的package包/类
/**
 * Creates Kafka topic if it does not exist.
 *
 * @param topic Kafka topic
 */
protected void checkAndCreateTopic(final String topic) {
    String hosts = config.getZookeeperHosts();
    ZkClient zkClient = new ZkClient(hosts, config.getZookeeperSessionTimeout(),
            config.getZookeeperConnectTimeout(), ZKStringSerializer$.MODULE$);
    ZkUtils zkUtils = new ZkUtils(zkClient, new ZkConnection(hosts), false);

    // FIXME(dbogun): race condition
    if (!AdminUtils.topicExists(zkUtils, topic)) {
        AdminUtils.createTopic(zkUtils, topic, 1, 1,
                AdminUtils.createTopic$default$5(), AdminUtils.createTopic$default$6());
    }
}
 
开发者ID:telstra,项目名称:open-kilda,代码行数:18,代码来源:AbstractTopology.java

示例14: SchedulerMonitor

import org.I0Itec.zkclient.ZkConnection; //导入依赖的package包/类
public SchedulerMonitor(String registryType, String servers) {
    if ("redis".equals(registryType)) {

    } else {
        ZkConnection zkConnection = new ZkConnection(servers);
        zkClient = new ZkClient(zkConnection, 3000);
    }
}
 
开发者ID:warlock-china,项目名称:azeroth,代码行数:9,代码来源:SchedulerMonitor.java

示例15: deleteTopic

import org.I0Itec.zkclient.ZkConnection; //导入依赖的package包/类
public void deleteTopic(final String topic) {
    log.debug("Deleting topic { name: {} }", topic);

    final ZkClient zkClient = new ZkClient(
        zookeeperConnect(),
        DEFAULT_ZK_SESSION_TIMEOUT_MS,
        DEFAULT_ZK_CONNECTION_TIMEOUT_MS,
        ZKStringSerializer$.MODULE$);
    final boolean isSecure = false;
    final ZkUtils zkUtils = new ZkUtils(zkClient, new ZkConnection(zookeeperConnect()), isSecure);
    AdminUtils.deleteTopic(zkUtils, topic);
    zkClient.close();
}
 
开发者ID:YMCoding,项目名称:kafka-0.11.0.0-src-with-comment,代码行数:14,代码来源:KafkaEmbedded.java


注:本文中的org.I0Itec.zkclient.ZkConnection类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。