Introduction
This repository contains some spring-cloud playground projects
Other repositories:
1. Spring cloud Gateway
2. ConfigServer
build, run and test
bash gradlew clean assemble
bash gradlew composeUp
bash gradlew composeDown
fetch configs from config-server using REST API
# http :8888/{application}/{profile}[/{label}]
# http :8888/{application}-{profile}.yml
# http :8888/{label}/{application}-{profile}.yml
# http :8888/{application}-{profile}.properties
# http :8888/{label}/{application}-{profile}.properties
http :8888/config-server-default.properties
http :8888/config-server-default.yml
http :8888/config-server/default/
links:
3. ConfigServer encryption / decryption
build, run and test
bash gradlew clean assemble
bash gradlew composeUp
bash gradlew composeDown
fetch configs from config-server using REST API
# http :8888/{application}/{profile}[/{label}]
# http :8888/{application}-{profile}.yml
# http :8888/{label}/{application}-{profile}.yml
# http :8888/{application}-{profile}.properties
# http :8888/{label}/{application}-{profile}.properties
http :8888/config-server-default.properties
http :8888/config-server-default.yml
http :8888/config-server/default/
links:
4. ConfigServer + ZipkinServer
build, run and test
# up infrastructure
bash gradlew clean assemble composeUp
# cleanup
bash gradlew composeDwown
testing services
# http :8888/{application}/{profile}[/{label}]
# http :8888/{application}-{profile}.yml
# http :8888/{label}/{application}-{profile}.yml
# http :8888/{application}-{profile}.properties
# http :8888/{label}/{application}-{profile}.properties
http :8888/config-server-default.properties
http :8888/config-server-default.yml
http :8888/zipkin-server/default
links:
5. ConfigServer + Vault
Spring Could Config Server + Vault
5.1. important to know
5.1.1. vault profile properties
VaultEnvironmentRepository.java - org/springframework/cloud/config/server/environment/VaultEnvironmentRepository.class
@ConfigurationProperties("spring.cloud.config.server.vault")
public class VaultEnvironmentRepository implements EnvironmentRepository, Ordered {
public static final String VAULT_TOKEN = "X-Vault-Token";
/** Vault host. Defaults to 127.0.0.1. */
@NotEmpty
private String host = "127.0.0.1";
/** Vault port. Defaults to 8200. */
@Range(min = 1, max = 65535)
private int port = 8200;
/** Vault scheme. Defaults to http. */
private String scheme = "http";
/** Vault backend. Defaults to secret. */
@NotEmpty
private String backend = "secret";
/** The key in vault shared by all applications. Defaults to application. Set to empty to disable. */
private String defaultKey = "application";
/** Vault profile separator. Defaults to comma. */
@NotEmpty
private String profileSeparator = ",";
// ...
5.1.2. override any property
-
override vault host in bootstrap.yml
spring: profiles: active: vault cloud: config: server: vault: host: vault
5.2. worked in separate: rabbit and vault in docker-compose + config-server run locally
build, run and test - not worked with confog-server in docker, run it in separate mode locally after vault docker will be bootstrapped
bash gradlew clean assemble composeUp bootRun
# do some...
bash gradlew composeDown
5.2.1. spring-cloud-config-vault
do unauthorized request
http :8888/application-default.properties
HTTP/1.1 400
Connection: close
Content-Type: application/json;charset=UTF-8
Date: Sun, 24 Sep 2017 07:08:14 GMT
Transfer-Encoding: chunked
X-Application-Context: application:vault:8888
{
"error": "Bad Request",
"exception": "java.lang.IllegalArgumentException",
"message": "Missing required header: X-Config-Token",
"path": "/application-default.properties",
"status": 400,
"timestamp": 1506236894133
}
do authorized request
http :8888/application-default.properties 'X-Config-Token:spring-cloud-examples-vault-token'
HTTP/1.1 200
Content-Length: 0
Content-Type: text/plain
Date: Sun, 24 Sep 2017 07:09:49 GMT
X-Application-Context: application:vault:8888
# nothing...
authorize vault in console
echo "spring-cloud-examples-vault-token" > ~/.vault-token
export VAULT_ADDR='http://0.0.0.0:8200'
add some data t ovault storage
vault write /secret/application foo=bar
Success! Data written to: secret/application
vault write /secret/bootstrap info='config-server + vault'
Success! Data written to: secret/bootstrap
fetch data
http :8888/application-default.properties 'X-Config-Token:spring-cloud-examples-vault-token'
HTTP/1.1 200
Content-Length: 8
Content-Type: text/plain
Date: Sun, 24 Sep 2017 07:09:49 GMT
X-Application-Context: application:vault:8888
foo: bar
http :8888/bootstrap/default 'X-Config-Token:spring-cloud-examples-vault-token'
HTTP/1.1 200
Content-Type: application/json;charset=UTF-8
Date: Sun, 24 Sep 2017 07:10:03 GMT
Transfer-Encoding: chunked
X-Application-Context: application:vault:8888
{
"label": null,
"name": "bootstrap",
"profiles": [
"default"
],
"propertySources": [
{
"name": "vault:bootstrap",
"source": {
"info": "config-server + vault"
}
},
{
"name": "vault:application",
"source": {
"foo": "bar"
}
}
],
"state": null,
"version": null
}
5.2.2. vault REST API
vault using REST API
http :8200/v1/sys/health
HTTP/1.1 200 OK
Cache-Control: no-store
Content-Length: 182
Content-Type: application/json
Date: Sun, 24 Sep 2017 06:07:03 GMT
{
"cluster_id": "55c792d9-e39b-15ca-d13a-1942240d5a5f",
"cluster_name": "vault-cluster",
"initialized": true,
"sealed": false,
"server_time_utc": 1506233223,
"standby": false,
"version": "0.8.3"
}
5.3. not worked all in docker-compose together
add in settings.gralde
include "docker:vault-rabbitmq-config"
build, run and test - not worked with confog-server in docker, run it in separate mode locally after vault docker will be bootstrapped
bash gradlew clean assemble composeUp
# do some...
bash gradlew composeDown
do unauthorized request
http :8888/application-default.properties
HTTP/1.1 400
Connection: close
Content-Type: application/json;charset=UTF-8
Date: Sun, 24 Sep 2017 07:08:14 GMT
Transfer-Encoding: chunked
X-Application-Context: application:vault:8888
{
"error": "Bad Request",
"exception": "java.lang.IllegalArgumentException",
"message": "Missing required header: X-Config-Token",
"path": "/application-default.properties",
"status": 400,
"timestamp": 1506236894133
}
do some authorized requests
http :8888/application-default.properties 'X-Config-Token:spring-cloud-examples-vault-token'
HTTP/1.1 200
Content-Length: 0
Content-Type: text/plain
Date: Sun, 24 Sep 2017 07:09:49 GMT
X-Application-Context: application:vault:8888
# nothing...
authorize vault in console
echo "spring-cloud-examples-vault-token" > ~/.vault-token
export VAULT_ADDR='http://0.0.0.0:8200'
add some data
vault write /secret/application foo=bar
Success! Data written to: secret/application
vault write /secret/bootstrap info='config-server + vault'
Success! Data written to: secret/bootstrap
fetch data
http :8888/application-default.properties 'X-Config-Token:spring-cloud-examples-vault-token'
HTTP/1.1 200
Content-Length: 8
Content-Type: text/plain
Date: Sun, 24 Sep 2017 07:13:50 GMT
X-Application-Context: application:vault:8888
foo: bar
http :8888/bootstrap-default.properties 'X-Config-Token:spring-cloud-examples-vault-token'
HTTP/1.1 200
Content-Length: 36
Content-Type: text/plain
Date: Sun, 24 Sep 2017 07:14:14 GMT
X-Application-Context: application:vault:8888
foo: bar
info: config-server + vault
6. ConfigServer native profile
important
spring:
profiles:
active:
- native
build, run and test
bash gradlew clean assemble composeUp
# do some..
bash gradlew composeDown
fetch configs from config-server using REST API
# http :8888/{application}/{profile}[/{label}]
# http :8888/{application}-{profile}.yml
# http :8888/{label}/{application}-{profile}.yml
# http :8888/{application}-{profile}.properties
# http :8888/{label}/{application}-{profile}.properties
http :8888/mq-default.yml
HTTP/1.1 200
Content-Length: 83
Content-Type: text/plain
Date: Sun, 24 Sep 2017 18:39:02 GMT
X-Application-Context: application:native,rabbitmq:8888
mq:
password: guest
server:
host: 0.0.0.0
port: 5672
username: guest
http :8888/db-default.properties
HTTP/1.1 200
Content-Length: 106
Content-Type: text/plain
Date: Sun, 24 Sep 2017 18:38:26 GMT
X-Application-Context: application:native,rabbitmq:8888
db.name: postgres
db.password: postgres
db.server.host: 0.0.0.0
db.server.port: 5432
db.username: postgres
http :8888/db/default
HTTP/1.1 200
Content-Type: application/json;charset=UTF-8
Date: Sun, 24 Sep 2017 18:39:40 GMT
Transfer-Encoding: chunked
X-Application-Context: application:native,rabbitmq:8888
{
"label": null,
"name": "db",
"profiles": [
"default"
],
"propertySources": [
{
"name": "classpath:/config/db.yml",
"source": {
"db.name": "${$DB_NAME:postgres}",
"db.password": "${$DB_PASSWORD:postgres}",
"db.server.host": "${$DB_SERVER_HOST:0.0.0.0}",
"db.server.port": "${$DB_SERVER_PORT:5432}",
"db.username": "${$DB_USERNAME:postgres}"
}
}
],
"state": null,
"version": null
}
http :8888/db/dev
HTTP/1.1 200
Content-Type: application/json;charset=UTF-8
Date: Sun, 24 Sep 2017 19:46:57 GMT
Transfer-Encoding: chunked
X-Application-Context: application:native:8888
{
"label": null,
"name": "db",
"profiles": [
"dev"
],
"propertySources": [
{
"name": "classpath:/config/db-dev.yml",
"source": {
"db.name": "postgres}",
"db.password": "postgres}",
"db.server.host": "127.0.0.1",
"db.server.port": 5432,
"db.username": "postgres}"
}
},
{
"name": "classpath:/config/db.yml",
"source": {
"db.name": "${$DB_NAME:postgres}",
"db.password": "${$DB_PASSWORD:postgres}",
"db.server.host": "${$DB_SERVER_HOST:0.0.0.0}",
"db.server.port": "${$DB_SERVER_PORT:5432}",
"db.username": "${$DB_USERNAME:postgres}"
}
}
],
"state": null,
"version": null
}
http :8888/mq-dev.yml
HTTP/1.1 200
Content-Length: 85
Content-Type: text/plain
Date: Sun, 24 Sep 2017 19:49:45 GMT
X-Application-Context: application:native:8888
mq:
password: guest
server:
host: 127.0.0.1
port: 5672
username: guest
7. Search Locations in ConfigServer Native
Search locations for Spring Could Config Server Native
important
spring:
profiles:
active: native
cloud:
config:
server:
native:
search-locations: >
classpath:/config,
classpath:/db,
classpath:/mq
build, run and test
bash gradlew clean assemble composeUp
# do some..
bash gradlew composeDown
def default db app configs
http :8888/db/default
HTTP/1.1 200
Content-Type: application/json;charset=UTF-8
Date: Sun, 24 Sep 2017 20:10:22 GMT
Transfer-Encoding: chunked
X-Application-Context: application:native,rabbitmq:8888
{
"label": null,
"name": "db",
"profiles": [
"default"
],
"propertySources": [
{
"name": "classpath:/db/db.yml",
"source": {
"db.name": "${$DB_NAME:postgres}",
"db.password": "${$DB_PASSWORD:postgres}",
"db.server.host": "${$DB_SERVER_HOST:0.0.0.0}",
"db.server.port": "${$DB_SERVER_PORT:5432}",
"db.username": "${$DB_USERNAME:postgres}"
}
}
],
"state": null,
"version": null
}
get db app dev profile configs
http :8888/db/dev
HTTP/1.1 200
Content-Type: application/json;charset=UTF-8
Date: Sun, 24 Sep 2017 20:11:33 GMT
Transfer-Encoding: chunked
X-Application-Context: application:native,rabbitmq:8888
{
"label": null,
"name": "db",
"profiles": [
"dev"
],
"propertySources": [
{
"name": "classpath:/db/db-dev.yml",
"source": {
"db.name": "postgres",
"db.password": "postgres",
"db.server.host": "127.0.0.1",
"db.server.port": 5432,
"db.username": "postgres"
}
},
{
"name": "classpath:/db/db.yml",
"source": {
"db.name": "${$DB_NAME:postgres}",
"db.password": "${$DB_PASSWORD:postgres}",
"db.server.host": "${$DB_SERVER_HOST:0.0.0.0}",
"db.server.port": "${$DB_SERVER_PORT:5432}",
"db.username": "${$DB_USERNAME:postgres}"
}
}
],
"state": null,
"version": null
}
db-dev.properties config file
# $ http :8888/db-dev.properties
# skip http metadata ...
db.name: postgres
db.password: postgres
db.server.host: 127.0.0.1
db.server.port: 5432
db.username: postgres
mq-dev.yaml config file
# $ http :8888/mq-dev.yaml
# skip http metadata ...
mq:
password: guest
server:
host: 127.0.0.1
port: 5672
username: guest
also JSON is possible too (8888/mq-dev.json)
{
"mq": {
"password": "guest",
"server": {
"host": "127.0.0.1",
"port": 5672
},
"username": "guest"
}
}
possible variants
# http :8888/{application}/{profile}[/{label}]
# http :8888/{application}-{profile}.yml
# http :8888/{label}/{application}-{profile}.yml
# http :8888/{application}-{profile}.properties
# http :8888/{label}/{application}-{profile}.properties
8. Override Spring Cloud Config
Spring Could Config Overrides
comment overridion
# ... spring.cloud.config.server
# overrides:
# foo: overridden foo
bootstrap to test no overrides
bash gradlew clean assemble composeUp
get not overridden config
http :8888/foo-dev.yaml
foo: baz
stop
bash gradlew composeDown
add overridion
# ... spring.cloud.config.server
overrides:
foo: overridden foo
bootstrap to test overrides config
bash gradlew clean assemble composeUp
get overriden config
cat config-server/src/main/resources/db/foo-dev.yml
foo: dev
# but
http :8888/foo-dev.yaml
foo: overridden foo
# as well as
http :8888/db-default.yml|grep foo
foo: overridden foo
# and
http :8888/db-notfound.yml|grep foo
foo: overridden foo
8888/foo/default
{
"label": null,
"name": "foo",
"profiles": [
"default"
],
"propertySources": [
{
"name": "overrides",
"source": {
"foo": "overridden foo"
}
},
{
"name": "classpath:/mq/foo.yml",
"source": {
"foo": "bar"
}
},
{
"name": "classpath:/db/foo.yml",
"source": {
"foo": "foo"
}
}
],
"state": null,
"version": null
}
8888/foo/dev
{
"label": null,
"name": "foo",
"profiles": [
"dev"
],
"propertySources": [
{
"name": "overrides",
"source": {
"foo": "overridden foo"
}
},
{
"name": "classpath:/mq/foo-dev.yml",
"source": {
"foo": "baz"
}
},
{
"name": "classpath:/db/foo-dev.yml",
"source": {
"foo": "dev"
}
},
{
"name": "classpath:/mq/foo.yml",
"source": {
"foo": "bar"
}
},
{
"name": "classpath:/db/foo.yml",
"source": {
"foo": "foo"
}
}
],
"state": null,
"version": null
}
9. Spring Cloud Task
10. Spring Cloud Dataflow Kubernetes
Unresolved directive in index.adoc - include::../../06-spring-cloud-dataflow-kubernetes/README.adoc[tags=content]
11. Spring Cloud Stream
Spring Could Stream
build, run and test
bash gradlew clean assemble composeUp
bash gradlew composeDown
links: