-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from sazzeo/kafka
Kafka
- Loading branch information
Showing
18 changed files
with
912 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,7 +18,6 @@ bin/ | |
!**/src/test/**/bin/ | ||
|
||
### IntelliJ IDEA ### | ||
.idea | ||
*.iws | ||
*.iml | ||
*.ipr | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,35 @@ | ||
# Micro Service 간 통신 | ||
``` text | ||
OpenFeign 이용하기 | ||
Kafka 이용하기 | ||
``` | ||
- userService에서 FeingClient를 이용한다. | ||
- @FeignClient 인터페이스를 작성한다. | ||
|
||
## @FeignClient 인터페이스 작성 | ||
|
||
```java | ||
@FeignClient(name="order-service") | ||
public interface OrderServiceClient { | ||
|
||
@GetMapping("/{userId}/orders") | ||
List<ResponseOrder> getOrders(@PathVariable String userId); | ||
|
||
} | ||
``` | ||
|
||
## 사용 | ||
|
||
- 빈으로 주입받아 사용한다. | ||
|
||
```java | ||
private final OrderServiceClient orderServiceClient; | ||
//중략 | ||
List<ResponseOrder> orders = orderServiceClient.getOrders; | ||
|
||
``` | ||
|
||
## 에러처리 | ||
|
||
- ErrorDecoder interface를 구현한다 | ||
- 이 인터페이스를 Bean으로 등록하면 ExceptionAdvice처럼 동작한다. | ||
|
||
- [ErrorDecoder구현 클래스 확인하기](https://github.com/sazzeo/msa-spring-cloud/blob/master/d-user-service/src/main/java/com/example/duserservice/error/FeignErrorDecoder.java) | ||
## 다른 service 끼리 kafka 통신 | ||
 | ||
- sink 와 source를 service 내부의 kafka class로 구현함 | ||
- kafka connector는 구동되어있어야함 | ||
|
||
## 동일 레플리카 service 끼리 kafka통신 | ||
 | ||
- kafka connector 이용 | ||
- kafka sink로 db에 직접 데이터 insert | ||
- kafka sink 정보 | ||
```yaml | ||
{ | ||
"name": "my-order-sink-connect", | ||
"config": { | ||
"connector.class": "io.confluent.connect.jdbc.JdbcSinkConnector", | ||
"connection.url": "jdbc:postgresql://spring-boot-study.cchzqclxtrke.ap-northeast-2.rds.amazonaws.com:5432/postgres", | ||
"connection.user": "db id", | ||
"connection.password": "db pw", | ||
"auto.create": "true", | ||
"auto.evolve": "true", | ||
"table.name.format":"msa_study.${topic}", | ||
"delete.enabled": "false", | ||
"tasks.max": "1", | ||
"topics": "orders" | ||
} | ||
} | ||
``` | ||
|
||
- 전송 data 포맷 | ||
 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters