본문 바로가기

전체 글50

Spring - Kafka 연동하기 Spring에 Kafka연동 테스트를 하기 위해 두개의 서버, server-a와 server-b를 생성하겠다. Dependency build.gradle.kts implementation ("org.springframework.kafka:spring-kafka:2.8.0") application.yml server: servlet: context-path: /server-a port: 8080 spring: kafka: bootstrap-servers: ${KAFKA_BROKER:localhost}:${KAFKA_BROKER_PORT:9092} listener.ack-mode: MANUAL_IMMEDIATE producer: acks: 1 key-serializer: org.apache.kafka.com.. 2021. 12. 4.
Kafka 설치하기 (Mac) 1. 설치 Kafka를 설치하는 방법은 여러가지가 있는데 여기서는 Apache 홈페이지에서 설명하는 명령어를 토대로 설치해본다. 우선 먼저 Kafka를 설치해야하는데 http://mirror.navercorp.com/apache/kafka/3.0.0/ 이 사이트에 들어가서 직접 들어가서 설치해도 되고 wget이나 curl명령어를 이용해서 설치해도 된다 wget http://mirror.navercorp.com/apache/kafka/3.0.0/kafka_2.13-3.0.0.tgz 설치를 한 다음 압축을 풀어줘야 한다 tar -xzf kafka_2.13-3.0.0.tgz cd kafka_2.13-3.0.0 2. 실행 다음으로 zookeeper와 kafka를 실행시켜주면 된다. # Start the ZooK.. 2021. 12. 4.
Design Patterns - Composite 그룹 전체와 개별 객체를 동일하게 처리할 수 있는 패턴 클라이언트 입장에서는 '전체'나 '부분'이나 모두 동일한 컴포넌트로 인식할 수 있는 계층 구조를 만든다 (Part-Whole Hierarchy) public interface Component { int getPrice(); } 계층 구조에 사용할 공통 Component 인터페이스를 정의한다 public class Item implements Component { private String name; private int price; public Item(String name, int price) { this.name = name; this.price = price; } @Override public int getPrice() { return thi.. 2021. 11. 29.
Design Patterns - Bridge 추상적인 것과 구체적인 것을 분리하여 연결하는 패턴 하나의 계층 구조일 때 보다 각기 나누었을 때 독립적인 계층 구조로 발전시킬 수 있다. public interface Skin { String getName(); } public interface Champion extends Skin { void move(); void skillQ(); void skillW(); void skillE(); void skillR(); } public class DefaultChampion implements Champion { private Skin skin; private String name; public DefaultChampion(Skin skin, String name) { this.skin = skin; th.. 2021. 11. 28.
Design Patterns - Adapter 기존 코드를 클라이언트가 사용하는 인터페이스의 구현체로 바꿔주는 패턴 클라이언트가 사용하는 인터페이스를 따르지 않는 기존 코드를 재사용할 수 있게 해준다 public class LoginHandler { UserDetailsService userDetailsService; public LoginHandler(UserDetailsService userDetailsService) { this.userDetailsService = userDetailsService; } public String login(String username, String password) { UserDetails userDetails = userDetailsService.loadUser(username); if (userDetails.. 2021. 11. 24.
Design Patterns - Prototype 기존 인스턴스를 복제하여 새로운 인스턴스를 만드는 방법 복제 기능을 갖추고 있는 기존 인스턴스를 프로토타입으로 사용해 새 인스턴스를 만들 수 있다. public class GithubIssue implements Cloneable { private int id; private String title; private GithubRepository repository; public GithubIssue(GithubRepository repository) { this.repository = repository; } public int getId() { return id; } public void setId(int id) { this.id = id; } public String getTitle() { retur.. 2021. 11. 22.