README version 0.1.0
A common accessor of zookeeper service implements with java. Zookeeper-Accessor was made up of this components:
- Publish: puslish a service with path /root(in config file)/service.id/version/sharding/endpoint:value.
- Subscribe: subcribe a service with path /root(in config file)/service.id/version/sharding.
- Accessor: client of zookeeper and auto reconnet zookeeper when recive exceptions.
- Email: yizer16[at]163[dot]com, yizer16[at]gmail[dot]com
The latest release code is available at Github.
You can build Zookeeper-Accessor from source:
You need setup maven to build this project: http://maven.apache.org/
Run this command and get the source:
git clone https://github.com/ZheYuan/Zookeeper-Accessor.git
Enter workcopy and install to local:
cd Zookeeper-Accessor
mvn install
Or
cd Zookeeper-Accessor
mvn assembly:assembly
This will generate two jars in ./target
directory.
default.config.path
is used to point out config file directory.
When use Accessor with config file in ./conf
, we can run class:
java -Ddefault.config.path=./conf
and write one line code:
ZkConfig config = new ZkConfig();
Or you can use ZkConfig provide publish method to set attribute.
This is a singleton client object of zookeper.
First call with a vaild ZkConfig
object:
Accessor accessor = Accessor.getInstance(config);
And then if wanna get the lastest singleton in somewhere, just call with a null
:
Accessor accessor2 = Accessor.getInstance(null);
This class is a service instance use ephemeral node of zookeeper. Each Publish object only publish once, or it will throws an OperationNotSupportedException
.
Publish publish = new Publish("test.service", "1", "0",
"PublishTestHandle", "127.0.0.1:80".getBytes());
accessor.publishService(publish);
// Remove the service
publish.die();
// This object's life cycle is same to accessor.
accessor.publishService(new Publish("test.service", "1", "0", "PublishTest", "127.0.0.1:81".getBytes());
This class is a client instance. Each Subscribe objcet only subcribe once, or it will throws an OperationNotSupportedException
.
Subscribe class is same to Publish class.
Zookeeper-Accessor is under the gpl v3.0 license. See the LICENSE file for details.