shushanfx / zkconfig-client

A config system for client.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ZKConfig client

Read config from zookeeper system, supporting rich api to handle the config. See zkconfig-server for more detail.

How to use

<dependencies>
    <dependency>
        <groupId>com.shushanfx</groupId>
        <artifactId>zkconfig-client</artifactId>
        <version>1.0-RELEASE</version>
    </dependency>
</dependencies>

If you can not down load this, use the jar package. see release.

You can use it like this:

package com.shushanfx.zconfig.client;

import com.shushanfx.zconfig.client.ZKConfig;
import com.shushanfx.zconfig.client.listener.ZKConfigDataListener;

import java.util.Scanner;

public class ZClientMain {
    public static void main(String[] args) {
        ZClient client = new ZClient();
        client.setServers("10.110.28.204:2181");
        client.setPath("/zkconfig/config/test");
        client.setMonitor(true);
        client.setMonitorPath("/zkconfig/connection");
        client.addListener(new ZNodeDataListener() {
            public void handle(ZNodeConfig config) {
                System.out.println("Read value from name: " + config.getString("name", "defaultValue"));
            }
        });
        client.connect();

        Scanner scanner = new Scanner(System.in);
        System.out.println("Press enter to exit.");
        scanner.nextLine();

    }
}

Refer

You can view the server config in zkconfig-server

About

A config system for client.

License:MIT License


Languages

Language:Java 100.0%