Java Code Examples for kafka.admin.AdminUtils#fetchTopicMetadataFromZk()
The following examples show how to use
kafka.admin.AdminUtils#fetchTopicMetadataFromZk() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TopicTest.java From hermes with Apache License 2.0 | 6 votes |
@Test public void createTopicInTestEnv() { String ZOOKEEPER_CONNECT = ""; ZkClient zkClient = new ZkClient(new ZkConnection(ZOOKEEPER_CONNECT)); ZkUtils zkUtils = new ZkUtils(zkClient, new ZkConnection(ZOOKEEPER_CONNECT), false); zkClient.setZkSerializer(new ZKStringSerializer()); int partition = 1; int replication = 1; String topic = String.format("kafka.test_create_topic_p%s_r%s", partition, replication); if (AdminUtils.topicExists(zkUtils, topic)) { TopicMetadata topicMetadata = AdminUtils.fetchTopicMetadataFromZk(topic, zkUtils); System.out.println(topicMetadata); AdminUtils.deleteTopic(zkUtils, topic); } AdminUtils.createTopic(zkUtils, topic, partition, replication, new Properties()); }
Example 2
Source File: MockKafka.java From kylin-on-parquet-v2 with Apache License 2.0 | 5 votes |
public MetadataResponse.TopicMetadata fetchTopicMeta(String topic) { ZkClient zkClient = new ZkClient(zkConnection); ZkUtils zkUtils = new ZkUtils(zkClient, zkConnection, false); zkClient.setZkSerializer(new ZKStringSerializer()); MetadataResponse.TopicMetadata topicMetadata = AdminUtils.fetchTopicMetadataFromZk(topic, zkUtils); zkClient.close(); return topicMetadata; }
Example 3
Source File: MockKafka.java From hermes with Apache License 2.0 | 5 votes |
public TopicMetadata fetchTopicMeta(String topic) { ZkClient zkClient = new ZkClient(zkServer.getConnection()); ZkUtils zkUtils = new ZkUtils(zkClient, zkServer.getConnection(), false); zkClient.setZkSerializer(new ZKStringSerializer()); TopicMetadata topicMetadata = AdminUtils.fetchTopicMetadataFromZk(topic, zkUtils); zkClient.close(); return topicMetadata; }
Example 4
Source File: MockKafka.java From kylin with Apache License 2.0 | 5 votes |
public MetadataResponse.TopicMetadata fetchTopicMeta(String topic) { ZkClient zkClient = new ZkClient(zkConnection); ZkUtils zkUtils = new ZkUtils(zkClient, zkConnection, false); zkClient.setZkSerializer(new ZKStringSerializer()); MetadataResponse.TopicMetadata topicMetadata = AdminUtils.fetchTopicMetadataFromZk(topic, zkUtils); zkClient.close(); return topicMetadata; }
Example 5
Source File: ZkConsumerCommand.java From azeroth with Apache License 2.0 | 4 votes |
public TopicMetadata getTopicMetadata(String topic) { TopicMetadata topicMetadata = AdminUtils.fetchTopicMetadataFromZk(topic, zkUtils); return topicMetadata; }
Example 6
Source File: Kafka09TopicProvisionTest.java From incubator-gobblin with Apache License 2.0 | 4 votes |
@Test (enabled=false) public void testTopicPartitionCreationCount() throws IOException, InterruptedException { String topic = "topicPartition4"; int clusterCount = _kafkaTestHelper.getClusterCount(); int partionCount = clusterCount/2; int zkPort = _kafkaTestHelper.getZookeeperPort(); Properties props = new Properties(); // Setting Topic Properties props.setProperty(KafkaWriterConfigurationKeys.KAFKA_TOPIC, topic); props.setProperty(KafkaWriterConfigurationKeys.REPLICATION_COUNT, String.valueOf(clusterCount)); props.setProperty(KafkaWriterConfigurationKeys.PARTITION_COUNT, String.valueOf(partionCount)); props.setProperty(KafkaWriterConfigurationKeys.CLUSTER_ZOOKEEPER, "localhost:"+zkPort); System.out.println(_kafkaTestHelper.getBootServersList()); // Setting Producer Properties props.setProperty(KafkaWriterConfigurationKeys.KAFKA_PRODUCER_CONFIG_PREFIX+"bootstrap.servers", _kafkaTestHelper.getBootServersList()); props.setProperty(KafkaWriterConfigurationKeys.KAFKA_PRODUCER_CONFIG_PREFIX+"value.serializer", "org.apache.kafka.common.serialization.StringSerializer"); Kafka09DataWriter<String, String> kafka09DataWriter = new Kafka09DataWriter<>(props); String zookeeperConnect = "localhost:"+_kafkaTestHelper.getZookeeperPort(); int sessionTimeoutMs = 10 * 1000; int connectionTimeoutMs = 8 * 1000; // 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, sessionTimeoutMs, connectionTimeoutMs, ZKStringSerializer$.MODULE$); boolean isSecureKafkaCluster = false; ZkUtils zkUtils = new ZkUtils(zkClient, new ZkConnection(zookeeperConnect), isSecureKafkaCluster); TopicMetadata metaData = AdminUtils.fetchTopicMetadataFromZk(topic,zkUtils); Assert.assertEquals(metaData.partitionsMetadata().size(), partionCount); }
Example 7
Source File: Kafka09TopicProvisionTest.java From incubator-gobblin with Apache License 2.0 | 4 votes |
@Test (enabled=false) public void testLiveTopicPartitionCreationCount() throws IOException, InterruptedException { String liveClusterCount = System.getProperty("live.cluster.count"); String liveZookeeper = System.getProperty("live.zookeeper"); String liveBroker = System.getProperty("live.broker"); String topic = System.getProperty("live.newtopic"); String topicReplicationCount = System.getProperty("live.newtopic.replicationCount"); String topicPartitionCount = System.getProperty("live.newtopic.partitionCount"); if(StringUtils.isEmpty(liveClusterCount)){ Assert.assertTrue(true); return; } if(StringUtils.isEmpty(topicPartitionCount)){ int clusterCount = Integer.parseInt(liveClusterCount); clusterCount--; int partionCount = clusterCount/2; topicReplicationCount = String.valueOf(clusterCount); topicPartitionCount = String.valueOf(partionCount); } Properties props = new Properties(); // Setting Topic Properties props.setProperty(KafkaWriterConfigurationKeys.KAFKA_TOPIC, topic); props.setProperty(KafkaWriterConfigurationKeys.REPLICATION_COUNT, topicReplicationCount); props.setProperty(KafkaWriterConfigurationKeys.PARTITION_COUNT, topicPartitionCount ); props.setProperty(KafkaWriterConfigurationKeys.CLUSTER_ZOOKEEPER, liveZookeeper); // Setting Producer Properties props.setProperty(KafkaWriterConfigurationKeys.KAFKA_PRODUCER_CONFIG_PREFIX+"bootstrap.servers", liveBroker); props.setProperty(KafkaWriterConfigurationKeys.KAFKA_PRODUCER_CONFIG_PREFIX+"value.serializer", "org.apache.kafka.common.serialization.StringSerializer"); Kafka09DataWriter<String, String> kafka09DataWriter = new Kafka09DataWriter<>(props); int sessionTimeoutMs = 10 * 1000; int connectionTimeoutMs = 8 * 1000; // 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( liveZookeeper, sessionTimeoutMs, connectionTimeoutMs, ZKStringSerializer$.MODULE$); boolean isSecureKafkaCluster = false; ZkUtils zkUtils = new ZkUtils(zkClient, new ZkConnection(liveZookeeper), isSecureKafkaCluster); TopicMetadata metaData = AdminUtils.fetchTopicMetadataFromZk(topic,zkUtils); Assert.assertEquals(metaData.partitionsMetadata().size(), Integer.parseInt(topicPartitionCount)); }