SpringCloud 의 Archaius - 동적 관리 속성 설정
1. Archaius 는 무엇 입 니까?
Archaius 는 속성 설정 파일 을 동적 으로 관리 하 는 데 사 용 됩 니 다.
Getting - Started 참조
* 도입 항목 중 * com. netflix. archaius archaius - core 0.6.0
로 컬 프로필 을 설정 원 으로 기본 값 으로 사용 합 니 다. Archaus 는 classpath 아래 config. properties 파일 을 찾 아 읽 습 니 다. 이 프로필 은 jar 패키지 의 루트 경로 에 포함 할 수 있 습 니 다.또한, 속성 archaius. configurationSource. additionalUrls 를 사용 하여 url 형식의 파일 을 포함 하고, 여러 파일 을 쉼표 로 분할 할 수 있 습 니 다.
아래 API 를 사용 하여 프로그램 에서 필요 한 속성 / / create a property whose value is type long and use 1000 as the default / / if the property is not defined DynamicLongProperty timeToWait = DynamicProperty Factory. getInstance (). getLongProperty ("lock. waitTime", 1000); /...ReentrantLock lock = ...; // ... lock.tryLock(timeToWait.get(), TimeUnit.MILLISECONDS); // timeToWait.get() returns up-to-date value of the property
기본 값: Archaius 는 속성 설정 을 분당 다시 불 러 옵 니 다. 다 중 속성 파일 을 읽 을 때 마지막 으로 읽 은 속성 은 앞의 같은 속성 을 덮어 씁 니 다.
우리 가 수정 할 수 있 는 시스템 속성 을 보 여 줍 니 다.
Operation HTTP action Notesarchaius. configurationSource. defaultFileName Archaius 가 기본적으로 불 러 오 는 설정 원본 속성 파일 이름 을 지정 합 니 다. 기본 값: classpath: config. properties config. properties archaius. fixedDelay PollingScheduler. initialDelayMills 로드 지연, 기본 값 30 초 30000 archaius. fixedDelay PollingScheduler. delayMills 두 번 의 속성 읽 기 시간 간격,기본 1 분 60000
고급 사용: configuration source 와 polling scheduler, 즉 동적 속성 설정 방안 을 스스로 설계 합 니 다.
간단 한 예
1. 설정 원본 가 져 오기
public class DynamicConfigurationSource implements PolledConfigurationSource { @Override public PollResult poll(boolean initial,Object checkPoint) throws Exception { Map map = new HashMap<>(); map.put("test",UUID.randomUUID().toString()); return PollResult.createFull(map); } }
2. 스케줄 러 정의
AbstractPollingScheduler scheduler = new FixedDelayPollingScheduler(2000,2000,false);
3. 동적 설정 정의
DynamicConfiguration configuration = new DynamicConfiguration(source,scheduler);
4. 단순 단원 테스트
@org.testng.annotations.Test
public void testArchaius() throws Exception { PolledConfigurationSource source = new DynamicConfigurationSource(); AbstractPollingScheduler scheduler = new FixedDelayPollingScheduler(2000,2000,false); DynamicConfiguration configuration = new DynamicConfiguration(source,scheduler); ConfigurationManager.install(configuration); final DynamicStringProperty stringProperty = DynamicPropertyFactory.getInstance().getStringProperty("test","nodata"); Helpers.subscribePrint(Observable.interval(1,TimeUnit.SECONDS).take(20).doOnNext(new Action1() { @Override public void call(Long aLong) { System.out.println(stringProperty.get()); } }),"test"); TimeUnit.MINUTES.sleep(1); }
이루어지다
1. 폴 링 퀘 스 트 시작
public synchronized void startPolling(PolledConfigurationSource source, AbstractPollingScheduler scheduler) { this.scheduler = scheduler; this.source = source; init(source, scheduler); scheduler.startPolling(source, this); }
2. 폴 링 의 Runnable 과 초기 화: 실현 은 일치 합 니 다.
PollResult result = null;
try {
result = source.poll(false,getNextCheckPoint(checkPoint));
checkPoint = result.getCheckPoint();
fireEvent(EventType.POLL_SUCCESS, result, null);
} catch (Throwable e) { log.error("Error getting result from polling source", e); fireEvent(EventType.POLL_FAILURE, null, e); return; } try { populateProperties(result, config); } catch (Throwable e) { log.error("Error occured applying properties", e); }
source. poll 방법, 즉 Polled ConfigurationSource 의 polled 를 호출 합 니 다. 저희 가 실현 하 는 데이터 원본 인 터 페 이 스 는 데이터 원본 (jdbc, 파일, scm 등) 을 사용자 정의 할 수 있 습 니 다.
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
다양한 언어의 JSONJSON은 Javascript 표기법을 사용하여 데이터 구조를 레이아웃하는 데이터 형식입니다. 그러나 Javascript가 코드에서 이러한 구조를 나타낼 수 있는 유일한 언어는 아닙니다. 저는 일반적으로 '객체'{}...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.