欧美一级特黄大片做受成人-亚洲成人一区二区电影-激情熟女一区二区三区-日韩专区欧美专区国产专区

如何進行consul注冊acltoken

本篇文章給大家分享的是有關(guān)如何進行consul注冊acl token,小編覺得挺實用的,因此分享給大家學(xué)習(xí),希望大家閱讀完這篇文章后可以有所收獲,話不多說,跟著小編一起來看看吧。

目前創(chuàng)新互聯(lián)已為1000多家的企業(yè)提供了網(wǎng)站建設(shè)、域名、雅安服務(wù)器托管、網(wǎng)站托管、企業(yè)網(wǎng)站設(shè)計、南海網(wǎng)站維護等服務(wù),公司將堅持客戶導(dǎo)向、應(yīng)用為本的策略,正道將秉承"和諧、參與、激情"的文化,與客戶和合作伙伴齊心協(xié)力一起成長,共同發(fā)展。

consul注冊 acl token 心跳 處理
已經(jīng)驗證 好使,心跳啟動成功啟動會有日志:Add Consul heartbeat for: xxxxxx

三個類放同意包下&在spring scanBasePackages 范圍內(nèi)

1.重寫ConsulHeartbeatAutoConfiguration

package com.support.consul;import com.ecwid.consul.v1.ConsulClient;import org.springframework.beans.factory.annotation.Value;import org.springframework.boot.autoconfigure.AutoConfigureAfter;import org.springframework.boot.autoconfigure.AutoConfigureBefore;import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;import org.springframework.cloud.client.ConditionalOnDiscoveryEnabled;import org.springframework.cloud.consul.ConditionalOnConsulEnabled;import org.springframework.cloud.consul.discovery.ConsulDiscoveryClientConfiguration;import org.springframework.cloud.consul.discovery.TtlScheduler;import org.springframework.cloud.consul.serviceregistry.ConsulServiceRegistryAutoConfiguration;import org.springframework.cloud.consul.support.ConsulHeartbeatAutoConfiguration;import org.springframework.context.annotation.Bean;import org.springframework.context.annotation.Configuration;/** * @Author luhaijun * @Description 重新定義YJConsulHeartbeatAutoConfiguration * @Date 2019/10/8 11:40 AM **/@Configuration@ConditionalOnConsulEnabled@ConditionalOnProperty({"spring.cloud.consul.discovery.heartbeat.enabled"})@ConditionalOnDiscoveryEnabled@AutoConfigureBefore({ConsulServiceRegistryAutoConfiguration.class, ConsulHeartbeatAutoConfiguration.class})@AutoConfigureAfter({ConsulDiscoveryClientConfiguration.class})public class YJConsulHeartbeatAutoConfiguration {@Value("${spring.cloud.consul.discovery.acl-token:null}")private String token;public YJConsulHeartbeatAutoConfiguration() {
    }@Bean    public YJHeartbeatProperties yjHeartbeatProperties() {return new YJHeartbeatProperties();
    }@Bean    public TtlScheduler ttlScheduler(YJHeartbeatProperties yjHeartbeatProperties, ConsulClient consulClient) {return new YJTtlScheduler(yjHeartbeatProperties, consulClient, token);
    }
}

2.重寫心跳Scheduler

package com.support.consul;import com.ecwid.consul.v1.ConsulClient;import org.apache.commons.logging.Log;import org.apache.commons.logging.LogFactory;import org.springframework.cloud.consul.discovery.TtlScheduler;import org.springframework.scheduling.TaskScheduler;import org.springframework.scheduling.concurrent.ConcurrentTaskScheduler;import java.util.Map;import java.util.concurrent.ConcurrentHashMap;import java.util.concurrent.Executors;import java.util.concurrent.ScheduledFuture;/** * @Author lbm * @Date 2019/10/3 4:54 下午 * @Description 重寫心跳Scheduler **/public class YJTtlScheduler extends TtlScheduler {private static final Log log = LogFactory.getLog(YJTtlScheduler.class);private final Map<String, ScheduledFuture> serviceHeartbeats = new ConcurrentHashMap<>();private final TaskScheduler scheduler = new ConcurrentTaskScheduler(Executors.newSingleThreadScheduledExecutor());private YJHeartbeatProperties configuration;private ConsulClient client;private String token;public YJTtlScheduler(YJHeartbeatProperties configuration, ConsulClient client, String token) {super(null, null);this.configuration = configuration;this.client = client;this.token = token;
    }@Override    public void add(String instanceId) {
        ScheduledFuture task = this.scheduler.scheduleAtFixedRate(new YJTtlScheduler.ConsulHeartbeatTask(instanceId), this.configuration.computeHeartbeatInterval().toStandardDuration().getMillis());
        ScheduledFuture previousTask = (ScheduledFuture) this.serviceHeartbeats.put(instanceId, task);if (previousTask != null) {
            previousTask.cancel(true);
        }log.info("Add Consul heartbeat for: " + instanceId);
    }@Override    public void remove(String instanceId) {
        ScheduledFuture task = (ScheduledFuture) this.serviceHeartbeats.get(instanceId);if (task != null) {
            task.cancel(true);
        }this.serviceHeartbeats.remove(instanceId);
    }private class ConsulHeartbeatTask implements Runnable {private String checkId;

        ConsulHeartbeatTask(String serviceId) {this.checkId = serviceId;if (!this.checkId.startsWith("service:")) {this.checkId = "service:" + this.checkId;
            }
        }@Override        public void run() {//調(diào)用ConsulClient api 帶token方法            YJTtlScheduler.this.client.agentCheckPass(this.checkId, null, token);if (log.isDebugEnabled()) {log.debug("Sending consul heartbeat for: " + this.checkId + ", token: " + token);
            }
        }
    }
}

3.自己配置HeartbeatProperties

package com.support.consul;import org.apache.commons.logging.Log;import org.apache.commons.logging.LogFactory;import org.joda.time.Period;import org.springframework.boot.context.properties.ConfigurationProperties;import org.springframework.core.style.ToStringCreator;import org.springframework.validation.annotation.Validated;import javax.validation.constraints.DecimalMax;import javax.validation.constraints.DecimalMin;import javax.validation.constraints.Min;import javax.validation.constraints.NotNull;@ConfigurationProperties(
        prefix = "spring.cloud.consul.discovery.heartbeat")@Validatedpublic class YJHeartbeatProperties {private static final Log log = LogFactory.getLog(YJHeartbeatProperties.class);boolean enabled = false;@Min(1L)private int ttlValue = 30;@NotNull    private String ttlUnit = "s";@DecimalMin("0.1")@DecimalMax("0.9")private double intervalRatio = 0.6666666666666666D;public YJHeartbeatProperties() {
    }protected Period computeHeartbeatInterval() {double interval = (double)this.ttlValue * this.intervalRatio;double max = Math.max(interval, 1.0D);int ttlMinus1 = this.ttlValue - 1;double min = Math.min((double)ttlMinus1, max);
        Period heartbeatInterval = new Period(Math.round(1000.0D * min));log.debug("Computed heartbeatInterval: " + heartbeatInterval);return heartbeatInterval;
    }public String getTtl() {return this.ttlValue + this.ttlUnit;
    }public boolean isEnabled() {return this.enabled;
    }public void setEnabled(boolean enabled) {this.enabled = enabled;
    }@Min(1L)public int getTtlValue() {return this.ttlValue;
    }public void setTtlValue(@Min(1L) int ttlValue) {this.ttlValue = ttlValue;
    }@NotNull    public String getTtlUnit() {return this.ttlUnit;
    }public void setTtlUnit(@NotNull String ttlUnit) {this.ttlUnit = ttlUnit;
    }@DecimalMin("0.1")@DecimalMax("0.9")public double getIntervalRatio() {return this.intervalRatio;
    }public void setIntervalRatio(@DecimalMin("0.1") @DecimalMax("0.9") double intervalRatio) {this.intervalRatio = intervalRatio;
    }@Override    public String toString() {return (new ToStringCreator(this)).append("enabled", this.enabled).append("ttlValue", this.ttlValue).append("ttlUnit", this.ttlUnit).append("intervalRatio", this.intervalRatio).toString();
    }
}

以上就是如何進行consul注冊acl token,小編相信有部分知識點可能是我們?nèi)粘9ぷ鲿姷交蛴玫降摹OM隳芡ㄟ^這篇文章學(xué)到更多知識。更多詳情敬請關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道。

標(biāo)題名稱:如何進行consul注冊acltoken
瀏覽地址:http://aaarwkj.com/article48/gihohp.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供手機網(wǎng)站建設(shè)、動態(tài)網(wǎng)站、Google、用戶體驗、標(biāo)簽優(yōu)化、網(wǎng)站收錄

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

營銷型網(wǎng)站建設(shè)
久久99精品久久久国产| 欧美一区二区三区久久束缚| 特黄日韩免费一区二区三区| 精品一区无遮挡免费网站| 国产系列在线播放一区二区三区| 日韩精品国产专区一区| 日本人妻精品一区二区| 91伊人手机在线观看| 日本久久高清免费观看| 国产精品国产三级区别| 蜜桃视频在线中文字幕| 日韩精品一区免费电影| 国产极品av一区二区三区| 91口爆吞精国产对白| 女厕所偷拍一区二区三区| 九色国产一区二区三区| 97国产免费全部免费观看| 激情五月婷婷中文字幕| 日日嗨av特一级黄淫片| 国产不卡视频观看网站| 国产一区二区黑丝美女| 日韩av在线专区观看| 一区二区精品福利视频| 欧美高清视频看片在线观看 | 久久婷婷国产综合精品青草| 成人精品淫片一级免费| 欧美性生活真实的视频| 蜜桃av网站免费观看| av免费在线观看麻豆| 中文字幕乱码亚洲影视| 久久精品国产亚洲av蜜点| 99久久免费看国产精品| 中文字幕国产精品一区二| 亚洲 欧美 日韩一区| 欧美一区二区亚洲天堂| 欧美日韩丝袜一区二区| 日韩人妻系列在线观看| 黄色资源网日韩三级一区二区| 一二区中文字幕在线观看| 亚洲日本欧美在线一区| 免费在线观看欧美色妇|