Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Config server/cloud bus #8

Merged
merged 2 commits into from
Aug 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions d-gateway/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ dependencies {
implementation 'org.springframework.cloud:spring-cloud-starter-bootstrap:3.1.3'
//actuator
implementation 'org.springframework.boot:spring-boot-starter-actuator:2.7.2'
implementation 'org.springframework.cloud:spring-cloud-starter-bus-amqp:3.1.2'
}

//버전 알아서 찾아주는 애
Expand Down
25 changes: 25 additions & 0 deletions d-gateway/src/main/java/com/example/gateway/GatewayController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.example.gateway;

import lombok.RequiredArgsConstructor;
import org.springframework.core.env.Environment;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@RequiredArgsConstructor
@RestController
public class GatewayController {
private final Environment env;

@GetMapping("health_check")
public Map<String, String> healthCheck() {

Map<String, String> responseMap = new HashMap<>();
responseMap.put("secret_key", env.getProperty("token.secret_key"));
responseMap.put("localServerPort", env.getProperty("local.server.port"));

return responseMap;
}
}
7 changes: 6 additions & 1 deletion d-gateway/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,16 @@ spring:
preLogger : true
postLogger : true

rabbitmq: #호스트 정보 기술 => ms는 클라이언트
host: 127.0.0.1
port: 5672 # 15672 는 rabbit mq 관리 페이지 접속용
username: guest
password: guest

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


1 change: 1 addition & 0 deletions d-user-service/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ dependencies {
implementation 'org.springframework.cloud:spring-cloud-starter-config'
implementation 'org.springframework.cloud:spring-cloud-starter-bootstrap:3.1.3'
implementation 'org.springframework.boot:spring-boot-starter-actuator:2.7.2' //spring cloud actuator
implementation 'org.springframework.cloud:spring-cloud-starter-bus-amqp:3.1.2'

}

Expand Down
9 changes: 8 additions & 1 deletion d-user-service/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ spring:
url: jdbc:h2:mem:testdb
driver-class-name: org.h2.Driver

# rabbitmq 정보
rabbitmq: #호스트 정보 기술 => ms는 클라이언트
host: 127.0.0.1
port: 5672 # 15672 는 rabbit mq 관리 페이지 접속용
username: guest
password: guest

#유레카 클라이언트 역할 기능 켜기
eureka:
instance:
Expand Down Expand Up @@ -44,6 +51,6 @@ management:
endpoints:
web:
exposure:
include: refresh , health , beans
include: refresh , health , beans , busrefresh


3 changes: 3 additions & 0 deletions e-config-service/build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
dependencies {

developmentOnly 'org.springframework.boot:spring-boot-devtools'
implementation 'org.springframework.boot:spring-boot-starter-actuator:2.7.2'
implementation 'org.springframework.cloud:spring-cloud-config-server:3.1.3'
implementation 'org.springframework.cloud:spring-cloud-starter-bus-amqp:3.1.2'
implementation 'org.springframework.cloud:spring-cloud-starter-bootstrap:3.1.3'

}

Expand Down
11 changes: 11 additions & 0 deletions e-config-service/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ spring:
# username: private repository 이용시 설정 추가
# password:

rabbitmq: #호스트 정보 기술 => ms는 클라이언트
host: 127.0.0.1
port: 5672 # 15672 는 rabbit mq 관리 페이지 접속용
username: guest
password: guest


# git이 아닌 로컬 폴더 이용시
#spring:
Expand All @@ -25,3 +31,8 @@ spring:
# server:
# native:
# search-locations: #로컬 폴더명
management:
endpoints:
web:
exposure:
include: health , busrefresh #host인 본인도 client 역할을 같이함.
37 changes: 24 additions & 13 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,37 @@ spring cloud config 로 yml파일 한번에 관리하기
3. d-gateway-service
4. ecommerce (Eureka Server)

## Config
## RabbitMq 설치 가이드

1. e-config-service
[rabbitmq 설치 가이드 in Notion](https://absorbing-brain-061.notion.site/Rabbit-MQ-c093020f8d614a738e8903d3cd29878c)

## 공통 Dependencies

```text
- Spring Cloud Config Server 의존성 추가
- application.yml 파일에 remote / local git repository 주소 등록 설정
implementation 'org.springframework.boot:spring-boot-starter-actuator:2.7.2'
implementation 'org.springframework.cloud:spring-cloud-starter-bootstrap:3.1.3'
implementation 'org.springframework.cloud:spring-cloud-starter-bus-amqp:3.1.2'
```

- amqp : 메시지 지향 미들웨어용 개방형 표준 응용 프로토콜
- rabbitmq 사용을 위해 추가함

## service
## yml 파일 설정

1. d-user-service
2. d-gateway-service
```yaml
spring:
rabbitmq:
host: 127.0.0.1
port: 5672
username: guest
password: guest


```text
- Spring Cloud Config 의존성 추가
- actuator , bootstrap 의존성 추가
- config-server 정보를 bootstrap.yml 파일에 추가
- actuator endpoint 정보를 application.yml 파일에 추가
management:
endpoints:
web:
exposure:
include: busrefresh
```

- rabbitMq server 주소와 정보 입력
- busrefresh : 전체파일 refresh용 endpoint