Skip to content

Commit c094ea1

Browse files
authored
Feat/202 (#203)
* Chore : 위치 변경 * Chore : 위치 변경 * Feat : HTTP브릿지 작성
1 parent 6b797fc commit c094ea1

File tree

7 files changed

+79
-7
lines changed

7 files changed

+79
-7
lines changed

docker-compose.yml

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ services:
2121
KAFKA_BROKER_ID: 1
2222
KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
2323
KAFKA_LISTENERS: INTERNAL://0.0.0.0:29092,EXTERNAL://0.0.0.0:9092
24-
KAFKA_ADVERTISED_LISTENERS: INTERNAL://kafka:29092,EXTERNAL://localhost:9092
24+
KAFKA_ADVERTISED_LISTENERS: INTERNAL://kafka:29092,EXTERNAL://kafka:9092
2525
KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: INTERNAL:PLAINTEXT,EXTERNAL:PLAINTEXT
2626
KAFKA_INTER_BROKER_LISTENER_NAME: INTERNAL
2727
KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1
@@ -41,8 +41,32 @@ services:
4141
- app-network
4242
restart: unless-stopped
4343

44-
volumes:
45-
minio-data:
44+
transcode:
45+
build: ./transcode
46+
container_name: transcode
47+
depends_on:
48+
- kafka
49+
env_file:
50+
- ./back/.env.default
51+
environment:
52+
- KAFKA_BOOTSTRAP=kafka:29092
53+
networks:
54+
- app-network
55+
restart: unless-stopped
56+
sns-bridge:
57+
build: ./sns-bridge
58+
container_name: sns-bridge
59+
depends_on:
60+
- kafka
61+
environment:
62+
- KAFKA_BOOTSTRAP=kafka:29092
63+
- KAFKA_TOPIC=s3-events
64+
- SNS_PORT=5000
65+
ports:
66+
- "5001:5000"
67+
networks:
68+
- app-network
69+
restart: on-failure
4670

4771
networks:
4872
app-network:

sns-bridge/Dockerfile

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
FROM python:3.11-slim
2+
3+
WORKDIR /app
4+
5+
COPY requirements.txt .
6+
RUN pip install --no-cache-dir -r requirements.txt
7+
8+
COPY app.py .
9+
10+
CMD ["python", "app.py"]

sns-bridge/app.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
from flask import Flask, request, jsonify
2+
from kafka import KafkaProducer
3+
import json
4+
import os
5+
6+
app = Flask(__name__)
7+
8+
KAFKA_BOOTSTRAP = os.getenv("KAFKA_BOOTSTRAP", "kafka:29092")
9+
KAFKA_TOPIC = os.getenv("KAFKA_TOPIC", "s3-events")
10+
11+
producer = KafkaProducer(
12+
bootstrap_servers=[KAFKA_BOOTSTRAP],
13+
value_serializer=lambda v: json.dumps(v).encode("utf-8")
14+
)
15+
16+
@app.route("/sns", methods=["POST"])
17+
def sns_listener():
18+
data = request.get_json(force=True)
19+
20+
# SNS 인증 요청 (SubscriptionConfirmation)
21+
if "Type" in data and data["Type"] == "SubscriptionConfirmation":
22+
print("SNS SubscriptionConfirmation received")
23+
print(f"Confirm URL: {data['SubscribeURL']}")
24+
return jsonify({"message": "Subscription confirmation received"}), 200
25+
26+
# 실제 S3 이벤트 메시지
27+
if "Type" in data and data["Type"] == "Notification":
28+
message = json.loads(data["Message"])
29+
print(f"📦 Received S3 event: {json.dumps(message, indent=2)}")
30+
producer.send(KAFKA_TOPIC, message)
31+
producer.flush()
32+
return jsonify({"status": "sent to kafka"}), 200
33+
34+
return jsonify({"status": "ignored"}), 200
35+
36+
37+
if __name__ == "__main__":
38+
port = int(os.getenv("SNS_PORT", 5000))
39+
app.run(host="0.0.0.0", port=port)

sns-bridge/requirements.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Flask==3.0.3
2+
kafka-python==2.0.2

Dockerfile renamed to transcode/Dockerfile

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,7 @@ RUN pip install --no-cache-dir -r requirements.txt
99
COPY consumer.py .
1010

1111
ENV KAFKA_TOPIC=s3-events
12-
ENV KAFKA_BOOTSTRAP=kafka:9092
13-
ENV MINIO_ENDPOINT=http://minio:9000
14-
ENV MINIO_ACCESS_KEY=minioadmin
15-
ENV MINIO_SECRET_KEY=minioadmin
12+
ENV KAFKA_BOOTSTRAP=kafka:29092
1613
ENV DOWNLOAD_DIR=/downloads
1714

1815
VOLUME ["/downloads"]
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)