Skip to content
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
2 changes: 2 additions & 0 deletions .github/workflows/deploy-with-docker-prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ jobs:
echo "MINIO_ACCESS_KEY=${{ secrets.PROD_MINIO_ACCESS_KEY }}" >> .env.prod
echo "MINIO_SECRET_KEY=${{ secrets.PROD_MINIO_SECRET_KEY }}" >> .env.prod
echo "MINIO_BUCKET=${{ secrets.PROD_MINIO_BUCKET}}" >> .env.prod
echo "KAFKA_BOOTSTRAP_SERVERS=${{secrets.PROD_KAFKA_BOOTSTRAP_SERVERS}}" >>.env.prod
echo "KAFKA_CONSUMER_GROUP_ID=${{secrets.PROD_KAFKA_CONSUMER_GROUP_ID}}" >>.env.prod

echo "${{ secrets.DOCKERHUB_PASSWORD }}" | docker login -u "${{ secrets.DOCKERHUB_USERNAME }}" --password-stdin

Expand Down
29 changes: 29 additions & 0 deletions docker-compose-local.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ services:
- DB_PASSWORD=${DB_PASSWORD}
- REDIS_PORT=6379
- REDIS_HOST=redis
- KAFKA_BOOTSTRAP_SERVERS=kafka:29092
- KAFKA_CONSUMER_GROUP_ID=devnogi-community-group
- JWT_SECRET_KEY=${JWT_SECRET_KEY}
depends_on:
mysql:
Expand Down Expand Up @@ -102,6 +104,33 @@ services:
interval: 5s
timeout: 3s
retries: 5

kafka:
image: confluentinc/cp-kafka:7.6.0
container_name: devnogi-community-kafka
ports:
- "9092:9092"
environment:
KAFKA_NODE_ID: 1
KAFKA_PROCESS_ROLES: broker,controller
KAFKA_BROKER: kafka:29092
KAFKA_LISTENERS: PLAINTEXT://0.0.0.0:29092,CONTROLLER://0.0.0.0:29093,PLAINTEXT_HOST://0.0.0.0:9092
KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://kafka:29092,PLAINTEXT_HOST://localhost:9092
KAFKA_CONTROLLER_LISTENER_NAMES: CONTROLLER
KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: CONTROLLER:PLAINTEXT,PLAINTEXT:PLAINTEXT,PLAINTEXT_HOST:PLAINTEXT
KAFKA_CONTROLLER_QUORUM_VOTERS: 1@kafka:29093
KAFKA_INTER_BROKER_LISTENER_NAME: PLAINTEXT
KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1
KAFKA_GROUP_INITIAL_REBALANCE_DELAY_MS: 0
CLUSTER_ID: MkU3OEVBNTcwNTJENDM2Qk
networks:
- my-network
healthcheck:
test: [ "CMD", "kafka-topics", "--bootstrap-server", "localhost:9092", "--list" ]
interval: 10s
timeout: 5s
retries: 5

networks:
my-network:
driver: bridge
3 changes: 2 additions & 1 deletion docker-compose-prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ services:
- MINIO_ACCESS_KEY=${MINIO_ACCESS_KEY} #ID
- MINIO_SECRET_KEY=${MINIO_SECRET_KEY} #PASSWORD
- MINIO_BUCKET=${MINIO_BUCKET}

- KAFKA_BOOTSTRAP_SERVERS=${PROD_KAFKA_BOOTSTRAP_SERVERS}
- KAFKA_CONSUMER_GROUP_ID=${PROD_KAFKA_CONSUMER_GROUP_ID}
- JWT_SECRET_KEY=${JWT_SECRET_KEY}
- TZ=Asia/Seoul

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package until.the.eternity.dcs.common.kafka;

import lombok.extern.slf4j.Slf4j;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Service;

@Service
@Slf4j
public class KafkaConsumerService {
@KafkaListener(topics = "test-topic", groupId = "devnogi-community-group")
public void consume(TestDTO message) {
log.info("컨수머 테스트 시작");
log.info("🎉 Kafka로부터 받은 메시지: {}", message);
log.info("컨수머 종료");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package until.the.eternity.dcs.common.kafka;

import static org.springframework.http.HttpStatus.NO_CONTENT;

import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/kafka")
@Slf4j
public class KafkaTestController {
private final KafkaTemplate<String, Object> kafkaTemplate;

public KafkaTestController(KafkaTemplate<String, Object> kafkaTemplate) {
this.kafkaTemplate = kafkaTemplate;
}

@PostMapping("/test/send")
public ResponseEntity<Void> sendMessage(@RequestBody TestDTO msg) {
log.info("kafka controller 테스트 시작: {}", msg);
kafkaTemplate.send("test-topic", msg);
log.info("kafka controller 테스트 끝");
return ResponseEntity.status(NO_CONTENT).build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package until.the.eternity.dcs.common.kafka;

public record TestDTO(String title, String content) {}
45 changes: 43 additions & 2 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,20 @@ spring:
config:
activate:
on-profile: local
kafka:
bootstrap-servers: ${KAFKA_BOOTSTRAP_SERVERS:kafka:29092}
producer:
key-serializer: org.apache.kafka.common.serialization.StringSerializer
value-serializer: org.springframework.kafka.support.serializer.JsonSerializer
consumer:
group-id: devnogi-community-group
auto-offset-reset: latest

key-deserializer: org.apache.kafka.common.serialization.StringDeserializer

value-deserializer: org.springframework.kafka.support.serializer.JsonDeserializer
properties:
spring.json.trusted.packages: "*"

decorator:
datasource:
Expand All @@ -124,6 +138,7 @@ logging:
until.the.eternity: DEBUG
until.the.eternity.dcs.common.filter: DEBUG


---
# 운영 환경
spring:
Expand All @@ -137,6 +152,17 @@ spring:
password: ${REDIS_PASSWORD:}
ssl:
enabled: false
kafka:
bootstrap-servers: ${PROD_KAFKA_BOOTSTRAP_SERVERS:localhost:9092}
consumer:
group-id: ${PROD_KAFKA_CONSUMER_GROUP_ID:devnogi-community-group}
auto-offset-reset: latest

key-deserializer: org.apache.kafka.common.serialization.StringDeserializer

value-deserializer: org.springframework.kafka.support.serializer.JsonDeserializer
properties:
spring.json.trusted.packages: "*"

springdoc:
swagger-ui:
Expand All @@ -148,6 +174,8 @@ minio:
secret-key: ${MINIO_SECRET_KEY:minioadmin}
bucket: ${MINIO_BUCKET:dcs-local-bucket}



decorator:
datasource:
p6spy:
Expand All @@ -156,6 +184,7 @@ decorator:
logging:
level:
until.the.eternity: INFO
org.springframework.kafka: DEBUG

---
# Docker 환경
Expand All @@ -168,8 +197,20 @@ spring:
host: ${REDIS_HOST:devnogi-community-redis}
port: ${REDIS_PORT:6379}
password: ${REDIS_PASSWORD:}

kafka:
bootstrap-servers: kafka:29092
producer:
key-serializer: org.apache.kafka.common.serialization.StringSerializer
value-serializer: org.springframework.kafka.support.serializer.JsonSerializer
consumer:
group-id: devnogi-community-group
auto-offset-reset: latest
key-deserializer: org.apache.kafka.common.serialization.StringDeserializer
value-deserializer: org.springframework.kafka.support.serializer.JsonDeserializer
properties:
spring.json.trusted.packages: "*"
logging:
level:
root: INFO
until.the.eternity: DEBUG
until.the.eternity: DEBUG
org.springframework.kafka: DEBUG
Loading