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


Java RackAwareMode类代码示例

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


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

示例1: setUpClass

import kafka.admin.RackAwareMode; //导入依赖的package包/类
@BeforeClass
public static void setUpClass() throws IOException {
    // setup Zookeeper
    zkServer = new EmbeddedZookeeper();
    zkConnect = ZKHOST + ":" + zkServer.port();
    zkClient = new ZkClient(zkConnect, 30000, 30000, ZKStringSerializer$.MODULE$);
    ZkUtils zkUtils = ZkUtils.apply(zkClient, false);

    // setup Broker
    Properties brokerProps = new Properties();
    brokerProps.setProperty("zookeeper.connect", zkConnect);
    brokerProps.setProperty("broker.id", "0");
    brokerProps.setProperty("log.dirs", Files.createTempDirectory("kafkaUtils-").toAbsolutePath().toString());
    brokerProps.setProperty("listeners", "PLAINTEXT://" + BROKERHOST + ":" + BROKERPORT);
    KafkaConfig config = new KafkaConfig(brokerProps);
    Time mock = new MockTime();
    kafkaServer = TestUtils.createServer(config, mock);

    // create topics
    AdminUtils.createTopic(zkUtils, TOPIC_R, 1, 1, new Properties(), RackAwareMode.Disabled$.MODULE$);
    AdminUtils.createTopic(zkUtils, TOPIC_S, 1, 1, new Properties(), RackAwareMode.Disabled$.MODULE$);

}
 
开发者ID:apache,项目名称:incubator-samoa,代码行数:24,代码来源:KafkaUtilsTest.java

示例2: setUpClass

import kafka.admin.RackAwareMode; //导入依赖的package包/类
@BeforeClass
public static void setUpClass() throws IOException {
    // setup Zookeeper
    zkServer = new EmbeddedZookeeper();
    zkConnect = ZKHOST + ":" + zkServer.port();
    zkClient = new ZkClient(zkConnect, 30000, 30000, ZKStringSerializer$.MODULE$);
    ZkUtils zkUtils = ZkUtils.apply(zkClient, false);

    // setup Broker
    Properties brokerProps = new Properties();
    brokerProps.setProperty("zookeeper.connect", zkConnect);
    brokerProps.setProperty("broker.id", "0");
    brokerProps.setProperty("log.dirs", Files.createTempDirectory("kafka-").toAbsolutePath().toString());
    brokerProps.setProperty("listeners", "PLAINTEXT://" + BROKERHOST + ":" + BROKERPORT);
    KafkaConfig config = new KafkaConfig(brokerProps);
    Time mock = new MockTime();
    kafkaServer = TestUtils.createServer(config, mock);

    // create topic
    AdminUtils.createTopic(zkUtils, TOPIC, 1, 1, new Properties(), RackAwareMode.Disabled$.MODULE$);

}
 
开发者ID:apache,项目名称:incubator-samoa,代码行数:23,代码来源:KafkaDestinationProcessorTest.java

示例3: setUpClass

import kafka.admin.RackAwareMode; //导入依赖的package包/类
@BeforeClass
public static void setUpClass() throws IOException {
    // setup Zookeeper
    zkServer = new EmbeddedZookeeper();
    zkConnect = ZKHOST + ":" + zkServer.port();
    zkClient = new ZkClient(zkConnect, 30000, 30000, ZKStringSerializer$.MODULE$);
    ZkUtils zkUtils = ZkUtils.apply(zkClient, false);

    // setup Broker
    Properties brokerProps = new Properties();
    brokerProps.setProperty("zookeeper.connect", zkConnect);
    brokerProps.setProperty("broker.id", "0");
    brokerProps.setProperty("log.dirs", Files.createTempDirectory("kafka-").toAbsolutePath().toString());
    brokerProps.setProperty("listeners", "PLAINTEXT://" + BROKERHOST + ":" + BROKERPORT);
    KafkaConfig config = new KafkaConfig(brokerProps);
    Time mock = new MockTime();
    kafkaServer = TestUtils.createServer(config, mock);

    // create topics        
    AdminUtils.createTopic(zkUtils, TOPIC_OOS, 1, 1, new Properties(), RackAwareMode.Disabled$.MODULE$);

}
 
开发者ID:apache,项目名称:incubator-samoa,代码行数:23,代码来源:KafkaEntranceProcessorTest.java

示例4: ensureTopicCreated

import kafka.admin.RackAwareMode; //导入依赖的package包/类
private void ensureTopicCreated(Map<String, ?> config) {
  ZkUtils zkUtils = createZkUtils(config);
  Map<String, List<PartitionInfo>> topics = _consumers.get(0).listTopics();
  long snapshotWindowMs = Long.parseLong((String) config.get(KafkaCruiseControlConfig.LOAD_SNAPSHOT_WINDOW_MS_CONFIG));
  int numSnapshotWindows = Integer.parseInt((String) config.get(KafkaCruiseControlConfig.NUM_LOAD_SNAPSHOTS_CONFIG));
  long retentionMs = (numSnapshotWindows * ADDITIONAL_SNAPSHOT_WINDOW_TO_RETAIN_FACTOR) * snapshotWindowMs;
  Properties props = new Properties();
  props.setProperty(LogConfig.RetentionMsProp(), Long.toString(retentionMs));
  props.setProperty(LogConfig.CleanupPolicyProp(), DEFAULT_CLEANUP_POLICY);
  int replicationFactor = Math.min(2, zkUtils.getAllBrokersInCluster().size());
  if (!topics.containsKey(_partitionMetricSampleStoreTopic)) {
    AdminUtils.createTopic(zkUtils, _partitionMetricSampleStoreTopic, 32, replicationFactor, props, RackAwareMode.Safe$.MODULE$);
  } else {
    AdminUtils.changeTopicConfig(zkUtils, _partitionMetricSampleStoreTopic, props);
  }

  if (!topics.containsKey(_brokerMetricSampleStoreTopic)) {
    AdminUtils.createTopic(zkUtils, _brokerMetricSampleStoreTopic, 32, replicationFactor, props, RackAwareMode.Safe$.MODULE$);
  } else {
    AdminUtils.changeTopicConfig(zkUtils, _brokerMetricSampleStoreTopic, props);
  }

  KafkaCruiseControlUtils.closeZkUtilsWithTimeout(zkUtils, 10000);
}
 
开发者ID:linkedin,项目名称:cruise-control,代码行数:25,代码来源:KafkaSampleStore.java

示例5: createTopic

import kafka.admin.RackAwareMode; //导入依赖的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

示例6: createTopic

import kafka.admin.RackAwareMode; //导入依赖的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

示例7: createTopic

import kafka.admin.RackAwareMode; //导入依赖的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

示例8: createMonitoringTopicIfNotExists

import kafka.admin.RackAwareMode; //导入依赖的package包/类
/**
 * Create the topic that the monitor uses to monitor the cluster.  This method attempts to create a topic so that all
 * the brokers in the cluster will have partitionToBrokerRatio partitions.  If the topic exists, but has different parameters
 * then this does nothing to update the parameters.
 *
 * TODO: Do we care about rack aware mode?  I would think no because we want to spread the topic over all brokers.
 * @param zkUrl zookeeper connection url
 * @param topic topic name
 * @param replicationFactor the replication factor for the topic
 * @param partitionToBrokerRatio This is multiplied by the number brokers to compute the number of partitions in the topic.
 * @param topicConfig additional parameters for the topic for example min.insync.replicas
 * @return the number of partitions created
 */
public static int createMonitoringTopicIfNotExists(String zkUrl, String topic, int replicationFactor,
    double partitionToBrokerRatio, Properties topicConfig) {
  ZkUtils zkUtils = ZkUtils.apply(zkUrl, ZK_SESSION_TIMEOUT_MS, ZK_CONNECTION_TIMEOUT_MS, JaasUtils.isZkSecurityEnabled());
  try {
    if (AdminUtils.topicExists(zkUtils, topic)) {
      return getPartitionNumForTopic(zkUrl, topic);
    }
    int brokerCount = zkUtils.getAllBrokersInCluster().size();
    int partitionCount = (int) Math.ceil(brokerCount * partitionToBrokerRatio);

    try {
      AdminUtils.createTopic(zkUtils, topic, partitionCount, replicationFactor, topicConfig, RackAwareMode.Enforced$.MODULE$);
    } catch (TopicExistsException e) {
      //There is a race condition with the consumer.
      LOG.debug("Monitoring topic " + topic + " already exists in cluster " + zkUrl, e);
      return getPartitionNumForTopic(zkUrl, topic);
    }
    LOG.info("Created monitoring topic " + topic + " in cluster " + zkUrl + " with " + partitionCount + " partitions, min ISR of "
      + topicConfig.get(KafkaConfig.MinInSyncReplicasProp()) + " and replication factor of " + replicationFactor + ".");

    return partitionCount;
  } finally {
    zkUtils.close();
  }
}
 
开发者ID:linkedin,项目名称:kafka-monitor,代码行数:39,代码来源:Utils.java

示例9: initKafka

import kafka.admin.RackAwareMode; //导入依赖的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

示例10: createTopic

import kafka.admin.RackAwareMode; //导入依赖的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

示例11: createTopic

import kafka.admin.RackAwareMode; //导入依赖的package包/类
/**
 * Creates a set of Kafka topics for each topic that does not already exist.
 *
 * @param zookeeperServers - The Zookeeper servers that are used by the Kafka Streams program. (not null)
 * @param topicNames - The topics that will be created. (not null)
 * @param partitions - The number of partitions that each of the topics will have.
 * @param replicationFactor - The replication factor of the topics that are created.
 */
public static void createTopic(
        final String zookeeperServers,
        final Set<String> topicNames,
        final int partitions,
        final int replicationFactor) {
    requireNonNull(zookeeperServers);
    requireNonNull(topicNames);

    ZkUtils zkUtils = null;
    try {
        zkUtils = ZkUtils.apply(new ZkClient(zookeeperServers, 30000, 30000, ZKStringSerializer$.MODULE$), false);
        for(final String topicName : topicNames) {
            if(!AdminUtils.topicExists(zkUtils, topicName)) {
                AdminUtils.createTopic(zkUtils, topicName, partitions, replicationFactor, new Properties(), RackAwareMode.Disabled$.MODULE$);
            }
        }
    }
    finally {
        if(zkUtils != null) {
            zkUtils.close();
        }
    }
}
 
开发者ID:apache,项目名称:incubator-rya,代码行数:32,代码来源:KafkaTopics.java

示例12: createKafkaConfig

import kafka.admin.RackAwareMode; //导入依赖的package包/类
public static Properties createKafkaConfig(int port, String zkConnect, boolean autoCreateTopic, int numPartitions) {
  final Option<File> noFile = scala.Option.apply(null);
  final Option<SecurityProtocol> noInterBrokerSecurityProtocol = scala.Option.apply(null);
  // new params for kafka 0.10.0
  Option<Properties> saslProperties = scala.Option.apply(null);
  Option<String> rack = scala.Option.apply(RackAwareMode.Enforced$.MODULE$.toString());

  Properties props = TestUtils.createBrokerConfig(
      0, zkConnect, false, false, port, noInterBrokerSecurityProtocol,
      noFile, saslProperties, true, false, TestUtils.RandomPort(), false, TestUtils.RandomPort(), false,
      TestUtils.RandomPort(), rack, 1);
  props.setProperty("auto.create.topics.enable", String.valueOf(autoCreateTopic));
  props.setProperty("num.partitions", String.valueOf(numPartitions));
  props.setProperty("offsets.topic.replication.factor", "1");
  return props;
}
 
开发者ID:streamsets,项目名称:datacollector,代码行数:17,代码来源:TestUtil1_0.java

示例13: createKafkaConfig

import kafka.admin.RackAwareMode; //导入依赖的package包/类
public static Properties createKafkaConfig(int port, String zkConnect, boolean autoCreateTopic, int numPartitions) {
  final Option<File> noFile = scala.Option.apply(null);
  final Option<SecurityProtocol> noInterBrokerSecurityProtocol = scala.Option.apply(null);
  // new params for kafka 0.10.0
  Option<Properties> saslProperties = scala.Option.apply(null);
  Option<String> rack = scala.Option.apply(RackAwareMode.Enforced$.MODULE$.toString());

  Properties props = TestUtils.createBrokerConfig(
      0, zkConnect, false, false, port, noInterBrokerSecurityProtocol,
      noFile, saslProperties, true, false, TestUtils.RandomPort(), false, TestUtils.RandomPort(), false,
      TestUtils.RandomPort(), rack);
  props.setProperty("auto.create.topics.enable", String.valueOf(autoCreateTopic));
  props.setProperty("num.partitions", String.valueOf(numPartitions));
  props.setProperty("offsets.topic.replication.factor", "1");
  return props;
}
 
开发者ID:streamsets,项目名称:datacollector,代码行数:17,代码来源:TestUtil11.java

示例14: createKafkaConfig

import kafka.admin.RackAwareMode; //导入依赖的package包/类
public static Properties createKafkaConfig(int port, String zkConnect, boolean autoCreateTopic, int numPartitions) {
  final Option<File> noFile = scala.Option.apply(null);
  final Option<SecurityProtocol> noInterBrokerSecurityProtocol = scala.Option.apply(null);
  // new params for kafka 0.10.0
  Option<Properties> saslProperties = scala.Option.apply(null);
  Option<String> rack = scala.Option.apply(RackAwareMode.Enforced$.MODULE$.toString());

  Properties props = TestUtils.createBrokerConfig(
      0, zkConnect, false, false, port, noInterBrokerSecurityProtocol,
      noFile, saslProperties, true, false, TestUtils.RandomPort(), false, TestUtils.RandomPort(), false,
      TestUtils.RandomPort(), rack);
  props.setProperty("auto.create.topics.enable", String.valueOf(autoCreateTopic));
  props.setProperty("num.partitions", String.valueOf(numPartitions));
  props.setProperty("offsets.topic.replication.factor", "1");
  props.setProperty("message.max.bytes", "500");
  return props;
}
 
开发者ID:streamsets,项目名称:datacollector,代码行数:18,代码来源:TestUtil10.java

示例15: createTopic

import kafka.admin.RackAwareMode; //导入依赖的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


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