Skip to content

Commit

Permalink
✨refactor: centralize configuration management with shared yaml files
Browse files Browse the repository at this point in the history
  • Loading branch information
Adnane Miliari committed Nov 27, 2024
1 parent 80b45eb commit bb3f9d3
Show file tree
Hide file tree
Showing 33 changed files with 258 additions and 697 deletions.
38 changes: 38 additions & 0 deletions common/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<parent>
<artifactId>demo-microservices</artifactId>
<groupId>dev.nano</groupId>
<version>1.0-SNAPSHOT</version>
</parent>

<modelVersion>4.0.0</modelVersion>
<artifactId>common</artifactId>

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-tracing-bridge-brave</artifactId>
</dependency>
<dependency>
<groupId>io.zipkin.reporter2</groupId>
<artifactId>zipkin-reporter-brave</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
</dependencies>
</project>
47 changes: 47 additions & 0 deletions common/src/main/resources/shared-application-default.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
management:
observations:
key-values:
application: ${spring.application.name}
tracing:
sampling:
probability: 1.0
enabled: true
zipkin:
tracing:
endpoint: http://localhost:9411/api/v2/spans
endpoints:
web:
exposure:
include: "*"
endpoint:
health:
show-details: always

spring:
datasource:
url: jdbc:postgresql://localhost:5432/${spring.application.name}
username: postgres
password: password
jpa:
hibernate:
ddl-auto: create-drop
properties:
hibernate:
dialect: org.hibernate.dialect.PostgreSQLDialect
format_sql: true
show-sql: true
open-in-view: false
rabbitmq:
addresses: localhost:5672

eureka:
client:
service-url:
defaultZone: http://localhost:8761/eureka
fetch-registry: true
register-with-eureka: true

logging:
pattern:
correlation: "[${spring.application.name:},%X{traceId:-},%X{spanId:-}]"
level: "%5p ${logging.pattern.correlation} %c{1.} : %m%n"
17 changes: 17 additions & 0 deletions common/src/main/resources/shared-application-docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
management:
zipkin:
tracing:
endpoint: http://zipkin:9411/api/v2/spans

spring:
datasource:
url: jdbc:postgresql://postgres:5432/${spring.application.name}
username: miliariadnane
password: password
rabbitmq:
addresses: rabbitmq:5672

eureka:
client:
service-url:
defaultZone: http://eureka-server:8761/eureka
16 changes: 16 additions & 0 deletions common/src/main/resources/shared-application-eks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
management:
zipkin:
tracing:
endpoint: http://zipkin:9411/api/v2/spans

spring:
datasource:
url: jdbc:postgresql://demo-microservices.csetxdk14qax.us-east-1.rds.amazonaws.com:5432/${spring.application.name}
username: ${DB_USERNAME}
password: ${DB_PASSWORD}
rabbitmq:
addresses: rabbitmq:5672
jpa:
hibernate:
ddl-auto: update

18 changes: 18 additions & 0 deletions common/src/main/resources/shared-application-kube.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
management:
zipkin:
tracing:
endpoint: http://zipkin:9411/api/v2/spans

spring:
datasource:
url: jdbc:postgresql://postgres:5432/${spring.application.name}
username: miliariadnane
password: password
rabbitmq:
addresses: rabbitmq:5672

eureka:
client:
service-url:
defaultZone: http://eureka-server:8761/eureka
enabled: false
5 changes: 5 additions & 0 deletions customer/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>dev.nano</groupId>
<artifactId>common</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>dev.nano</groupId>
<artifactId>amqp</artifactId>
Expand Down
44 changes: 0 additions & 44 deletions customer/src/main/resources/application-docker.yml

This file was deleted.

37 changes: 0 additions & 37 deletions customer/src/main/resources/application-eks.yml

This file was deleted.

45 changes: 0 additions & 45 deletions customer/src/main/resources/application-kube.yml

This file was deleted.

44 changes: 4 additions & 40 deletions customer/src/main/resources/application.yml
Original file line number Diff line number Diff line change
@@ -1,48 +1,12 @@
#Server
server:
port: 8001
servlet:
context-path: /customer
error:
include-message: always
#Management
management:
endpoints:
web:
exposure:
include: "*"
endpoint:
health:
show-details: always
#Spring
include-message: always

spring:
application:
name: customer
datasource:
url: jdbc:postgresql://localhost:5432/customer
username: postgres
password: password
zipkin:
base-url: http://localhost:9411
rabbitmq:
addresses: localhost:5672 # not http, because is a message queue protocol
jpa:
hibernate:
ddl-auto: create-drop
properties:
hibernate:
dialect: org.hibernate.dialect.PostgreSQLDialect
format_sql: true
show-sql: true
#Eureka-Client
eureka:
client:
service-url:
defaultZone: http://localhost:8761/eureka
fetch-registry: true
register-with-eureka: true
logging:
pattern:
# Logging pattern containing traceId and spanId; no longer provided through Sleuth by default
level: "%5p [${spring.application.name:},%X{traceId:-},%X{spanId:-}]"

config:
import: classpath:shared-application-${spring.profiles.active}.yml
15 changes: 13 additions & 2 deletions eureka-server/src/main/resources/application-docker.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,32 @@
#Server
server:
port: 8761

#Spring
spring:
application:
name: eureka-server
zipkin:
baseUrl: http://zipkin:9411

#Management
management:
observations:
key-values:
application: ${spring.application.name}
tracing:
sampling:
probability: 1.0
enabled: true
zipkin:
tracing:
endpoint: http://zipkin:9411/api/v2/spans
endpoints:
web:
exposure:
include: "*"
endpoint:
health:
show-details: always

#Eureka-Server
eureka:
client:
Expand Down
Loading

0 comments on commit bb3f9d3

Please sign in to comment.