λŒ€μš©λŸ‰ 처리 ν…ŒμŠ€νŠΈ κ΅¬ν˜„ ν”„λ‘œμ νŠΈ - 1 (κ°œμš” 및 ν™˜κ²½μ„ΈνŒ…)

2024. 6. 5. 15:08ㆍProject

λ°˜μ‘ν˜•

πŸ“˜ ν”„λ‘œμ νŠΈ κ°œμš”

  • λͺ©μ : Redis와 Kafkaλ₯Ό μ‚¬μš©ν•˜μ—¬ μ‹€μ‹œκ°„ λŒ€μš©λŸ‰ 데이터λ₯Ό μ²˜λ¦¬ν•˜λŠ” Spring Boot λ°±μ—”λ“œμ™€ React ν”„λ‘ νŠΈμ—”λ“œ ν…œν”Œλ¦Ώμ„ μ œκ³΅ν•©λ‹ˆλ‹€.
  • λŒ€μƒ: μ‹€μ œ ν˜„μ—…μ—μ„œλŠ” κ²½ν—˜ν•˜κΈ° μ–΄λ €μš΄ λŒ€μš©λŸ‰ 처리λ₯Ό ν…ŒμŠ€νŠΈν•˜κ³ μž ν•˜λŠ” κ°œλ°œμžλ“€μ„ μœ„ν•œ ν…œν”Œλ¦Ώμž…λ‹ˆλ‹€.
  • 효과: μ‹€μ‹œκ°„ 데이터 처리 및 λΆ€ν•˜ ν…ŒμŠ€νŠΈλ₯Ό 톡해 λŒ€μš©λŸ‰ 처리 μ‹œμŠ€ν…œμ„ κ°„μ ‘μ μœΌλ‘œ κ²½ν—˜ν•  수 μžˆμŠ΅λ‹ˆλ‹€.

πŸ”§ μ‚¬μš© 기술

ꡬ뢄 기술
λ°±μ—”λ“œ Spring Boot, Redis, Kafka
ν”„λ‘ νŠΈμ—”λ“œ React
기타 Apache JMeter, Docker, Socket

πŸ› οΈ 사전 μ€€λΉ„

μš°μ„  μ•„λž˜ μ†Œν”„νŠΈμ›¨μ–΄λ₯Ό μ„€μΉ˜ν•œ ν™˜κ²½μ„ κ΅¬μ„±ν•©λ‹ˆλ‹€.

  • Docker
  • Docker Compose
  • JDK 17+
  • Apache JMeter (λΆ€ν•˜ ν…ŒμŠ€νŠΈμš©)
  • Eclipse (Spring Boot, React ν”„λ‘œμ νŠΈ μ„ΈνŒ… ν•„μš”)

ν”„λ‘œκ·Έλž¨ μ„€μΉ˜ κ³Όμ •κ³Ό Spring Boot/React μ„ΈνŒ…μ€ μƒλž΅ν•©λ‹ˆλ‹€. λ‹€λ₯Έ 글을 μ°Έκ³  λ°”λžλ‹ˆλ‹€.

βš™οΈ ν”„λ‘œμ νŠΈ ν™˜κ²½ μ„ΈνŒ…

πŸ”Ή 도컀λ₯Ό μ΄μš©ν•œ Redis, Kafka ν™˜κ²½ ꡬ성

1. docker-compose.yml μž‘μ„±

ν”„λ‘œμ νŠΈ 폴더 μ•„λž˜μ— docker-compose.yml νŒŒμΌμ„ μƒμ„±ν•©λ‹ˆλ‹€. 이 νŒŒμΌμ€ Docker Composeλ₯Ό μ‚¬μš©ν•˜μ—¬ μ—¬λŸ¬ μ»¨ν…Œμ΄λ„ˆ μ„œλΉ„μŠ€λ₯Ό μ„€μ •ν•©λ‹ˆλ‹€.

services:
  zookeeper:
    image: bitnami/zookeeper:latest
    environment:
      - ALLOW_ANONYMOUS_LOGIN=yes
    ports:
      - "2181:2181"

  kafka:
    image: bitnami/kafka:latest
    ports:
      - "9092:9092"
    environment:
      - KAFKA_CFG_ZOOKEEPER_CONNECT=zookeeper:2181
      - ALLOW_PLAINTEXT_LISTENER=yes
      - KAFKA_CFG_LISTENERS=PLAINTEXT://0.0.0.0:9092
      - KAFKA_CFG_ADVERTISED_LISTENERS=PLAINTEXT://localhost:9092
      - KAFKA_BROKER_ID=1
    depends_on:
      - zookeeper

  redis:
    image: redis:latest
    ports:
      - "6379:6379"

  app:
    build: .
    ports:
      - "8080:8080"
    depends_on:
      - redis
      - kafka
      - zookeeper
    environment:
      - SPRING_REDIS_HOST=redis
      - SPRING_REDIS_PORT=6379
      - SPRING_KAFKA_BOOTSTRAP_SERVERS=kafka:9092

2. Dockerfile μž‘μ„±

ν”„λ‘œμ νŠΈ 폴더 μ•„λž˜μ— Dockerfile νŒŒμΌμ„ μƒμ„±ν•©λ‹ˆλ‹€.

# Use the official Maven image with OpenJDK 17 to build the application
FROM maven:3.8.4-openjdk-17 AS build
WORKDIR /app
COPY . .
RUN mvn clean package -DskipTests

# Use the official OpenJDK image to run the application
FROM openjdk:17-jdk-slim
WORKDIR /app
COPY --from=build /app/target/*.jar app.jar
EXPOSE 8080
ENTRYPOINT ["java", "-jar", "app.jar"]

Dockerfile은 두 λ‹¨κ³„λ‘œ κ΅¬μ„±λœ λ©€ν‹°μŠ€ν…Œμ΄μ§€ λΉŒλ“œλ₯Ό μ‚¬μš©ν•©λ‹ˆλ‹€.

  • λΉŒλ“œ 단계: Mavenκ³Ό OpenJDK 17을 μ‚¬μš©ν•˜μ—¬ μ• ν”Œλ¦¬μΌ€μ΄μ…˜μ„ λΉŒλ“œν•©λ‹ˆλ‹€.
  • μ‹€ν–‰ 단계: μŠ¬λ¦Όν•œ OpenJDK 이미지λ₯Ό μ‚¬μš©ν•˜μ—¬ λΉŒλ“œλœ JAR νŒŒμΌμ„ μ‹€ν–‰ν•©λ‹ˆλ‹€. μ΄λŠ” 이미지 크기λ₯Ό 쀄이고, μ‹€ν–‰ ν™˜κ²½μ„ κ°„μ†Œν™”ν•©λ‹ˆλ‹€.

3. Docker λΉŒλ“œ

docker-compose.yml이 μžˆλŠ” ν΄λ”λ‘œ μ΄λ™ν•˜μ—¬ λͺ…λ Ήμ–΄λ₯Ό μ‹€ν–‰ν•©λ‹ˆλ‹€.

docker-compose up --build

μ•„λž˜ λͺ…λ Ήμ–΄λ‘œ λͺ¨λ“  μ»¨ν…Œμ΄λ„ˆκ°€ μ •μƒμ μœΌλ‘œ μ‹€ν–‰λ˜λŠ”μ§€ ν™•μΈν•©λ‹ˆλ‹€.

docker-compose ps

πŸ”Ή Spring Boot ν™˜κ²½ μ„€μ •

Dockerμ—μ„œ μ„€μ •ν•œ Redis와 Kafka와 Spring Bootκ°€ 톡신 κ°€λŠ₯ν•˜λ„λ‘ 포트λ₯Ό μ„€μ •ν•©λ‹ˆλ‹€.

spring.redis.host=127.0.0.1
spring.redis.port=6379

spring.kafka.bootstrap-servers=127.0.0.1:9092

πŸ”— 전체 μ†ŒμŠ€μ½”λ“œ

GitHubμ—μ„œ 전체 μ†ŒμŠ€μ½”λ“œλ₯Ό 확인할 수 μžˆμŠ΅λ‹ˆλ‹€: GitHub - sonhoil/Largevolume: λŒ€μš©λŸ‰ 처리 μ‹œμŠ€ν…œ ν…ŒμŠ€νŠΈ ν™˜κ²½ κ΅¬ν˜„ ν”„λ‘œμ νŠΈ

GitHub - sonhoil/Largevolume: λŒ€μš©λŸ‰ 처리 μ‹œμŠ€ν…œ ν…ŒμŠ€νŠΈ ν™˜κ²½ κ΅¬ν˜„ ν”„λ‘œμ νŠΈ
GitHub - sonhoil/Largevolume: λŒ€μš©λŸ‰ 처리 μ‹œμŠ€ν…œ ν…ŒμŠ€νŠΈ ν™˜κ²½ κ΅¬ν˜„ ν”„λ‘œμ νŠΈ
λ°˜μ‘ν˜•