Java Code Examples for org.I0Itec.zkclient.ZkClient#setZkSerializer()

The following examples show how to use org.I0Itec.zkclient.ZkClient#setZkSerializer() . 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 vote down vote up
@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 vote down vote up
public void createTopic(String topic, int partition, int replication) {
    ZkClient zkClient = new ZkClient(zkConnection);
    ZkUtils zkUtils = new ZkUtils(zkClient, zkConnection, false);
    zkClient.setZkSerializer(new ZKStringSerializer());
    AdminUtils.createTopic(zkUtils, topic, partition, replication, new Properties(), null);
    zkClient.close();
}
 
Example 3
Source File: MockKafka.java    From kylin-on-parquet-v2 with Apache License 2.0 5 votes vote down vote up
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 4
Source File: MockKafka.java    From kylin-on-parquet-v2 with Apache License 2.0 5 votes vote down vote up
/**
 * Delete may not work
 *
 * @param topic
 */
public void deleteTopic(String topic) {
    ZkClient zkClient = new ZkClient(zkConnection);
    ZkUtils zkUtils = new ZkUtils(zkClient, zkConnection, false);
    zkClient.setZkSerializer(new ZKStringSerializer());
    AdminUtils.deleteTopic(zkUtils, topic);
    zkClient.close();
}
 
Example 5
Source File: MockKafka.java    From hermes with Apache License 2.0 5 votes vote down vote up
public void createTopic(String topic, int partition, int replication) {
	ZkClient zkClient = new ZkClient(zkServer.getConnection());
	ZkUtils zkUtils = new ZkUtils(zkClient, zkServer.getConnection(), false);
	zkClient.setZkSerializer(new ZKStringSerializer());
	AdminUtils.createTopic(zkUtils, topic, partition, replication, new Properties());
	zkClient.close();
}
 
Example 6
Source File: MockKafka.java    From hermes with Apache License 2.0 5 votes vote down vote up
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 7
Source File: MockKafka.java    From hermes with Apache License 2.0 5 votes vote down vote up
/**
 * Delete may not work
 * 
 * @param topic
 */
public void deleteTopic(String topic) {
	ZkClient zkClient = new ZkClient(zkServer.getConnection());
	ZkUtils zkUtils = new ZkUtils(zkClient, zkServer.getConnection(), false);
	zkClient.setZkSerializer(new ZKStringSerializer());
	AdminUtils.deleteTopic(zkUtils, topic);
	zkClient.close();
}
 
Example 8
Source File: MockKafka.java    From kylin with Apache License 2.0 5 votes vote down vote up
public void createTopic(String topic, int partition, int replication) {
    ZkClient zkClient = new ZkClient(zkConnection);
    ZkUtils zkUtils = new ZkUtils(zkClient, zkConnection, false);
    zkClient.setZkSerializer(new ZKStringSerializer());
    AdminUtils.createTopic(zkUtils, topic, partition, replication, new Properties(), null);
    zkClient.close();
}
 
Example 9
Source File: MockKafka.java    From kylin with Apache License 2.0 5 votes vote down vote up
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 10
Source File: MockKafka.java    From kylin with Apache License 2.0 5 votes vote down vote up
/**
 * Delete may not work
 *
 * @param topic
 */
public void deleteTopic(String topic) {
    ZkClient zkClient = new ZkClient(zkConnection);
    ZkUtils zkUtils = new ZkUtils(zkClient, zkConnection, false);
    zkClient.setZkSerializer(new ZKStringSerializer());
    AdminUtils.deleteTopic(zkUtils, topic);
    zkClient.close();
}
 
Example 11
Source File: ZkConfigSaver.java    From learning-hadoop with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) {
	if ((args == null) || (args.length < 1)) {
		throw new RuntimeException("需要指定输出目录名");
	}
	loadProperties();

	ZkClient client = new ZkClient(ZK_ADDRESS, ZK_TIMEOUT);
	client.setZkSerializer(new ZkUtils.StringSerializer(ZK_CONF_ENCODING));

	File confDir = new File(args[0]);
	confDir.mkdirs();

	saveConfigs(client, ZK_CONFIG_ROOTNODE, confDir);
}
 
Example 12
Source File: ZkConfigPublisher.java    From learning-hadoop with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) {
	loadProperties();

	ZkClient client = new ZkClient(ZK_ADDRESS, ZK_TIMEOUT);
	client.setZkSerializer(new ZkUtils.StringSerializer(ZK_CONF_ENCODING));

	File confDir = new File(CONF_DIR);
	if ((!confDir.exists()) || (!confDir.isDirectory())) {
		System.err.println("错误: 配置目录" + confDir + "不存在或非法! ");
		System.exit(1);
	}

	publishConfigs(client, ZK_CONFIG_ROOTNODE, confDir);
}
 
Example 13
Source File: DynamicBrokerSelector.java    From incubator-pinot with Apache License 2.0 5 votes vote down vote up
public DynamicBrokerSelector(String zkServers) {
  ZkClient zkClient = new ZkClient(zkServers);
  zkClient.setZkSerializer(new BytesPushThroughSerializer());
  zkClient.waitUntilConnected(60, TimeUnit.SECONDS);
  zkClient.subscribeDataChanges(ExternalViewReader.BROKER_EXTERNAL_VIEW_PATH, this);
  evReader = new ExternalViewReader(zkClient);
  refresh();
}
 
Example 14
Source File: Util.java    From kafka-service-broker with Apache License 2.0 4 votes vote down vote up
ZkClient getClient() {
    ZkClient zc = new ZkClient(getConnection());
    zc.setZkSerializer(ZKStringSerializer$.MODULE$);
    return zc;
}