Skip to content

JDK-Plus/spring-boot-starter-etcd

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

一、如何引入

<dependency>
    <groupId>plus.jdk</groupId>
    <artifactId>spring-boot-starter-etcd</artifactId>
    <version>1.0.6</version>
</dependency>

二、etcd的引用配置

plus.jdk.etcd.enabled=true
plus.jdk.etcd.user-name=admin
plus.jdk.etcd.password=123456
plus.jdk.etcd.endpoints=http://ip1:2379,http://ip2:2379,http://ip3:2379

java 使用etcd不建议使用证书,因为SslContext Builder只支持PEM格式的PKCS#8私钥文件。

三、在项目中引用

下面给出一个使用示例。

import lombok.extern.slf4j.Slf4j;
import plus.jdk.etcd.annotation.EtcdNode;
import plus.jdk.etcd.global.EtcdClient;
import plus.jdk.scheduled.annotation.Scheduled;
import plus.jdk.scheduled.global.IScheduled;

import javax.annotation.Resource;
import java.lang.management.ManagementFactory;
import java.lang.management.OperatingSystemMXBean;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Random;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

@Slf4j
@Scheduled(expr = "0/1 * * * * *")
public class LoadAverageScheduledTask extends IScheduled {


    @EtcdNode(path = "/example/system/aim/loadAverage")
    private volatile double maxLoadAverage = 2.0;

    @EtcdNode(path = "/example/system/aim/random/length")
    private volatile int maxRandomLen = 500000;

    @Resource
    private EtcdClient etcdClient;

    private final ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(5, 200,
            0, TimeUnit.SECONDS,
            new ArrayBlockingQueue<>(200));

    @Override
    protected void doInCronJob() {
        String data = etcdClient.getFirstKV("/example", String.class);
    }
}

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages