zkconfig-resources

A ZooKeeper based configuration resources holder

License

License

The Artistic License 2.0
Categories

Categories

config Application Layer Libs Configuration
GroupId

GroupId

com.github.hai046
ArtifactId

ArtifactId

zkconfig-resources
Last Version

Last Version

1.0.0
Release Date

Release Date

Type

Type

jar
Description

Description

zkconfig-resources
A ZooKeeper based configuration resources holder
Project URL

Project URL

https://github.com/hai046/zkconfig-resources
Source Code Management

Source Code Management

https://github.com/hai046/zkconfig-resources.git

Download zkconfig-resources

How to add to project

<!-- https://jarcasting.com/artifacts/com.github.hai046/zkconfig-resources/ -->
<dependency>
    <groupId>com.github.hai046</groupId>
    <artifactId>zkconfig-resources</artifactId>
    <version>1.0.0</version>
</dependency>
// https://jarcasting.com/artifacts/com.github.hai046/zkconfig-resources/
implementation 'com.github.hai046:zkconfig-resources:1.0.0'
// https://jarcasting.com/artifacts/com.github.hai046/zkconfig-resources/
implementation ("com.github.hai046:zkconfig-resources:1.0.0")
'com.github.hai046:zkconfig-resources:jar:1.0.0'
<dependency org="com.github.hai046" name="zkconfig-resources" rev="1.0.0">
  <artifact name="zkconfig-resources" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.github.hai046', module='zkconfig-resources', version='1.0.0')
)
libraryDependencies += "com.github.hai046" % "zkconfig-resources" % "1.0.0"
[com.github.hai046/zkconfig-resources "1.0.0"]

Dependencies

compile (8)

Group / Artifact Type Version
org.apache.commons : commons-dbcp2 jar 2.0.1
org.springframework : spring-jdbc jar 4.1.4.RELEASE
redis.clients : jedis jar 2.6.2
org.slf4j : slf4j-api jar 1.7.10
com.google.guava : guava jar 18.0
org.apache.curator : curator-recipes jar 2.7.1
com.fasterxml.jackson.core : jackson-databind jar 2.5.0
commons-beanutils : commons-beanutils jar 1.9.2

test (1)

Group / Artifact Type Version
junit : junit jar 4.12

Project Modules

There are no modules declared in this project.

zkconfig-resources

A ZooKeeper config based MySQL and jedis connection pool wrapper.

  • Pool config changes on the fly
  • MySQL connection pool support sharding
  • jdk 1.8 only

Get Started

<dependency>
    <groupId>com.github.phantomthief</groupId>
    <artifactId>zkconfig-resources</artifactId>
    <version>1.0.0</version>
</dependency>

Usage

Redis connection pool example:

try (CuratorFramework client = CuratorFrameworkFactory.newClient("127.0.0.1:2181",
        new ExponentialBackoffRetry(10000, 3));
        ZkBasedJedis jedis = new ZkBasedJedis("/jedis/clientConfig", client);) { // declare a jedis client using a config from zk's node.

    jedis.get().set("key1", "value1"); // exec jedis commands, don't worry about returning the connection back to the pool.
    System.out.println("get key:" + jedis.get().get("key1")); // exec jedis commands.

    // pipeline operation
    Random random = new Random();
    List<Integer> list = Arrays.asList(1, 2, 3, 4);

    jedis.pipeline(list,
            (pipeline, key) -> pipeline.sadd("prefix:" + key, random.nextInt(100) + "")); // pipeline write

    Map<Integer, Long> multiCount = jedis.pipeline(list,
            (pipeline, key) -> pipeline.scard("prefix:" + key)); // pipeline read
    System.out.println(multiCount);

    Map<Integer, Boolean> customCodecPipelineResult = jedis.pipeline(list,
            (pipeline, key) -> pipeline.scard("prefix:" + key), value -> value > 10); // pipeline with customize decoder
    System.out.println(customCodecPipelineResult);
}

MySQL connection pool example:

try (CuratorFramework client = CuratorFrameworkFactory.newClient("127.0.0.1:2181",
        new ExponentialBackoffRetry(10000, 3));
        DataSource dataSource = new ZkBasedBasicDataSource("/dataSource/defaultMySqlConfig",
            client);) {
    // using the dataSource as you like.
}

Configuration

Redis connection pool config example:

create /jedis/clientConfig {"t1":"127.0.0.1:6379","t2":"127.0.0.1:6380","t3@p@ssword":"127.0.0.1:6381"}

Data source config example:

create /dataSource/defaultMySqlConfig {"pass":"p@ssword","user":"root","url":"jdbc:mysql://127.0.0.1:3306/test"}

Versions

Version
1.0.0