Spring Cloud - 26. Spring Cloud Bus

Config Server

// https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-actuator
implementation 'org.springframework.boot:spring-boot-starter-actuator'

// https://mvnrepository.com/artifact/org.springframework.cloud/spring-cloud-starter-bus-amqp
implementation 'org.springframework.cloud:spring-cloud-starter-bus-amqp'

Users Microservice

// https://mvnrepository.com/artifact/org.springframework.cloud/spring-cloud-starter-bus-amqp
implementation 'org.springframework.cloud:spring-cloud-starter-bus-amqp'

Gateway Service

// https://mvnrepository.com/artifact/org.springframework.cloud/spring-cloud-starter-bus-amqp
implementation 'org.springframework.cloud:spring-cloud-starter-bus-amqp'

Config Server

server:
port: 8888

spring:
application:
name: config-service
profiles:
active: native
cloud:
config:
server:
native:
search-locations: file://${user.home}/dev/study/Spring-Cloud/gateway/git-local-repository
rabbitmq:
host: 127.0.0.1
port: 5672
username: guest
password: guest

management:
endpoints:
web:
exposure:
include: health, busrefresh

#spring:
# application:
# name: config-service
# cloud:
# config:
# server:
# git:
# uri: https://github.com/ckck803/spring-cloud-config
## uri: file:///Users/dongwoo-yang/dev/study/Spring-Cloud/gateway/git-local-repository

User Service

server:
port: 0

spring:
application:
name: user-service

h2:
console:
enabled: true
settings:
web-allow-others: true

datasource:
username: sa
password:
driver-class-name: org.h2.Driver
url: jdbc:h2:mem:testdb

rabbitmq:
host: 127.0.0.1
port: 5672
username: guest
password: guest

eureka:
instance:
instanceId: ${spring.application.name}:${spring.application.instance_id:${random.value}}
client:
register-with-eureka: true
fetch-registry: true
service-url:
defaultZone: http://localhost:8761/eureka

greeting:
message: Welcome to the Simple E-commerce.

management:
endpoints:
web:
exposure:
include: refresh, health, beans, busrefresh

#token:
# expiration_time: 84600000
# secret: user_token
spring:
cloud:
config:
uri: http://127.0.0.1:8888
name: config-server
# profiles:
# active: dev

#spring:
# cloud:
# config:
# uri: http://127.0.0.1:8888
# name: ecommerce
# profiles:
# active: dev

gateway service

server:
port: 8080

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

spring:
application:
name: apigateway-service
cloud:
gateway:
default-filters:
- name: GlobalFilter
args:
baseMessage: Spring Cloud Gateway Global Filter
preLogger: true
postLogger: true

routes:
- id: user-service
uri: lb://USER-SERVICE
predicates:
- Path=/user-service/login
- Method=POST
filters:
- RemoveRequestHeader=Cookie
- RewritePath=/user-service/(?<segment>.*), /$\{segment}

- id: user-service
uri: lb://USER-SERVICE
predicates:
- Path=/user-service/users
- Method=POST
filters:
- RemoveRequestHeader=Cookie
- RewritePath=/user-service/(?<segment>.*), /$\{segment}

- id: user-service
uri: lb://USER-SERVICE
predicates:
- Path=/user-service/**
- Method=GET
filters:
- RemoveRequestHeader=Cookie
- RewritePath=/user-service/(?<segment>.*), /$\{segment}
- AuthorizationHeaderFilter

- id: user-service
uri: lb://USER-SERVICE
predicates:
- Path=/user-service/actuator/**
- Method=GET, POST
filters:
- RemoveRequestHeader=Cookie
- RewritePath=/user-service/(?<segment>.*), /$\{segment}

- id: catalog-service
uri: lb://CATALOG-SERVICE
predicates:
- Path=/catalog-service/**
filters:
- CustomFilter

- id: order-service
uri: lb://ORDER-SERVICE
predicates:
- Path=/order-service/**
filters:
- CustomFilter
rabbitmq:
host: 127.0.0.1
port: 5672
username: guest
password: guest

token:
secret: user_token

management:
endpoints:
web:
exposure:
include: refresh, health, beans, httptrace, busrefresh
spring:
cloud:
config:
uri: http://127.0.0.1:8888
name: config-server
# profiles:
# active: dev

#spring:
# cloud:
# config:
# uri: http://127.0.0.1:8888
# name: ecommerce
# profiles:
# active: dev
Share