zk-registry - A library for registering services to Zoo-Keeper
as Discovery Services.
After registering, you are able to check health status about the service -
by using zk-srv-discovery
or with
org.apache.curator.x.discovery.ServiceDiscovery
instance.
- ZooKeeper 3.5.x
-
ZooKeeper 3.4.x - need to make exclusion from curator's dependency:
<dependency> <groupId>org.apache.curator</groupId> <artifactId>curator-x-discovery-server</artifactId> <version>4.0.1</version> <exclusions> <exclusion> <groupId>org.apache.zookeeper</groupId> <artifactId>zookeeper</artifactId> </exclusion> </exclusions> </dependency>
and add zk dependency:
<dependency> <groupId>org.apache.zookeeper</groupId> <artifactId>zookeeper</artifactId> <version>3.4.10</version> </dependency>
-
Implements static methods - register,unregister.
- Connecting to Zk server as Zk client.
- Zk client wrapped with
CuratorFramework
. - Use the client for registering the service as Service-Discovery.
- ServiceDiscovery wrapped with
curator-x-discovery-server
- Run ZooKeeper server.
- Run
zk-srv-discovery
with ZooKeeper address - Register services using
zk-registry
library (or runzk-registry-service
). - Use
zk-srv-discovery
web service to get information on registered services.
The library contains a method which registering a service to the discovery service:
public static int register(final String zkAddress,
final String serviceName,
final int servicePort,
final String version,
final String metaData)
Examples:
register("123.54.23.1:2181", "Worker_1", 19005, "v1", "Mock Service 1")
register("123.54.23.1:2181", "Worker_2", 18006, "v3", "")
A standalone service for registration to Discovery service.
zk-registry
library
Depends on zk-registry
library.
Edit environment variables:
ENV_VAR | Example | Mandatory |
---|---|---|
zk_address | zk_address=123.45.23.1:2181 | [x] |
service_name | service_name=Worker_1 | [x] |
service_port | service_port=18005 | [x] |
version | version=1.0.0 | [x] |
meta | meta="" | [ ] |
Example of running an image:
docker run -d --name zk-register-Worker_1 \
-e zk_address=DENNIS-V:2181
-e service_name=WORKER_1 \
-e service_port=18006 \
-e version=1.0.3 \
-e meta="HELLO WORLD" \
zk-registry-service:1.0.0
-
To build a docker image run:
docker build --build-arg version=${version} -t ${image}
for example:
docker build --build-arg version=1.0.0 \ -t zk-registry-service:1.0.0
-
Docker image build script: Run
./image-build.sh