1 Şubat 2021 Pazartesi

SpringCloud Config Server Sunucu İçin application.properties Ayarları

Giriş
Tüm ayarlar
spring.cloud.config.server.XXX ile belli oluyor.
XXX yerine 
- jdbc
- native
- git

kullanılabilir

Konfigürasyon Dosya İsimleri
Konfigürasyon Dosya İsimleri belli bir formatta olmalı. Açıklaması şöyle
Let’s take a moment to discuss the naming convention for the configuration files. The filenames are important and must be in a certain pattern for your microservices to pick them up:

/{application}/{profile}[/{label}]
/{application}-{profile}.yml
/{label}/{application}-{profile}.yml
/{application}-{profile}.properties
/{label}/{application}-{profile}.properties

Where:

{application} is the name of your microservice specified via your microservice’s spring.application.name property. In this case, service-one and service-two.
{profile} matches the list of profiles your microservice is running via the spring.profiles.active property. In this case, profile1 and profile2.
{label} is an additional descriptor usually corresponding to a version control branch, e.g. dev or stg. It can be manually set via the spring.cloud.config.label property in the microservice’s bootstrap.properties file or set on the command line (-Dspring.cloud.config.label).
Açıklaması şöyle. Yani "neo4j-client.yaml" dosyasına erişmek için "localhost:8888/neo4j-client/default" adresine erişmek gerekir. Burada profile verilmediği için default ismine sahip dosyaya erişilir.
Many tutorials use the /{application}/{profile} notation. The /{application} piece references the name you give your client application. This is an arbitrary name, except that your config file (in our case, yaml) needs to have the same name. Config file naming follows the pattern {application}-{profile}. If you do not specify a -{profile} (e.g., development, production) on the config file name, it uses the default profile.
Örnek - github
Eğer sunucu 8888 adresinde çalışıyorsa, config-client uygulamasını taklit etmek için şöyle yaparız. Burada profile değeri development, label değeri ise main
curl http://localhost:8888/config-client/development/main
Neden label olarak main verildiğinin açıklaması şöyle
You must provide the branch name if you are using the URL with the label as if not provided it will take default as master( as it defaulted in GitHub), however, GitHub has changed it to main, so you need to provide main in the path

Örnek - JDBC
Şöyle yaparız
spring.cloud.config.server.jdbc.sql= SELECT PROP_KEY, VALUE from PROPERTIES where APPLICATION=? and PROFILE=? and LABEL=?
spring.cloud.config.server.jdbc.order=1
Veri tabanı tablosu şöyledir
create table properties(
  id integer not null auto_increment,
  CREATED_ON datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  APPLICATION varchar(255),
  PROFILE varchar(255),
  LABEL varchar(255),
  PROP_KEY varchar(255),
  VALUE varchar(255), 
primary key (id)
);

INSERT INTO properties (APPLICATION, PROFILE, LABEL, PROP_KEY, VALUE) VALUES
('spring-cloud-config-client', 'dev', 'latest', 'URL_A', 'https://client-urlA-dev.com'),
('spring-cloud-config-client', 'dev', 'latest', 'URL_B', 'https://client-urlB-dev.com'),
('spring-cloud-config-client', 'test', 'latest', 'URL_A', 'https://client-urlA-test.com'),
('spring-cloud-config-client2','dev', 'latest', 'URL_A', 'https://client2-urlA-dev.com'),
('spring-cloud-config-client2','test', 'latest', 'URL_A', 'https://client2-urlA-t.com');
Ulaşmak için şöyle yaparız
http://<server port-no>/<APPLICATION>/<PROFILE>/<LABEL> 
http://localhost:8888/spring-cloud-config-client/dev/latest

Örnek - Dosya Sistemi
Şöyle yaparız
server.port=8888
spring.cloud.config.server.native.search-locations=/path/to/config/folder
spring.security.user.name=configUser
spring.security.user.password=configPass
Örnek - Docker
Şöyle yaparız
server.port: 8888 
spring.cloud.config.server.native.searchLocations: file:${PWD}/config-repo 
management.endpoint.health.show-details: "ALWAYS" 
management.endpoints.web.exposure.include: "*" 
logging.level.root: info  
--- 
spring.config.activate.on-profile: docker 
spring.cloud.config.server.native.searchLocations: file:/config-repo  
Örnek - git Dosya Sistemi
Açıklaması şöyle
It's standard practice to run a configuration server at port 8888. For a Windows environment, kindly keep an additional "/". For other environments, "//" will work. spring.cloud.config.server.git.uri=file://d:/config-properties
Şöyle yaparız
spring.application.name=hello-config-server
server.port=8888
spring.cloud.config.server.git.uri=file:///d:/config-properties
Dosyaları git'e eklemek için şöyle yaparız
git init .

creat foo.properties

git add foo.properties
git commit -m 'very first configuration'
Örnek - git Sunucusu
Şöyle yaparız
spring.cloud.config.server.git.uri=https://github.com/abcd/springboot
spring.cloud.config.server.git.uri.username=test
spring.cloud.config.server.git.uri.password=test
Örnek
Şöyle yaparız. Burada git repository clone'lanıyor
server: port: 8888 spring: cloud: config: server: git: uri: https://github.com/NavaliaHQ/api-config.git searchPaths: - '{application}' username: GIT_USER #update with github username password: GIT_PASSWORD #update with github password clone-on-start: true default-label: master


Hiç yorum yok:

Yorum Gönder