티스토리 뷰
728x90
🔎 Kafka Proxy란?
Kafka는 기본적으로 **Kafka protocol (TCP 기반)**을 사용합니다.
하지만 Kafka Proxy는 이를 HTTP/REST 인터페이스로 감싸주는 역할을 해요.
목적 설명
✅ Kafka를 REST로 접근 | POST/GET 방식으로 Kafka에 메시지 전송, 조회 |
✅ Kafka 클라이언트 설치 없이 연동 | IoT, 외부 API 서버 등과 연동에 유리 |
✅ K8s에서 서비스화 쉬움 | Ingress, Service 등 활용 가능 |
🔌 대표 Kafka 프록시 종류 (모두 무료)
프록시 이름 | 설명 | 라이센스 |
Confluent REST Proxy | 가장 많이 쓰는 공식 REST 프록시 | Apache 2.0 (무료) |
Landoop Kafka Rest Proxy (Fast Data) | 간단한 REST 프록시 | Apache 2.0 |
Franz Kafka Proxy | KafkaJS 기반, Node.js용 | MIT |
Strimzi Kafka Bridge | Kafka to HTTP 브리지 (Kubernetes용) | Apache 2.0 |
✅ 추천: Strimzi Kafka Bridge
왜 추천하나요?
- K8s 환경에 최적화되어 있음
- Helm Chart 및 Operator 제공
- REST API로 Kafka 토픽에 메시지 전송 가능
☸️ Strimzi Kafka Bridge 설치 (Kubernetes)
1. Strimzi Operator 설치 (Helm)
helm repo add strimzi https://strimzi.io/charts/
helm install strimzi-kafka-operator strimzi/strimzi-kafka-operator
2. KafkaBridge CR 배포
apiVersion: kafka.strimzi.io/v1beta2
kind: KafkaBridge
metadata:
name: my-bridge
spec:
replicas: 1
bootstrapServers: my-cluster-kafka-bootstrap:9092
http:
port: 8080
my-cluster-kafka-bootstrap은 Kafka Cluster의 내부 주소입니다.
Bridge가 생성되면 HTTP 엔드포인트로 메시지를 Kafka에 전송할 수 있어요.
🧪 메시지 전송 예시 (curl)
curl -X POST http://bridge-service:8080/topics/my-topic \
-H "Content-Type: application/json" \
-d '{
"records": [
{ "key": "user1", "value": { "name": "홍길동", "age": 30 } }
]
}'
Kafka를 직접 몰라도 외부 시스템에서 HTTP로 메시지를 보낼 수 있어요! 🚀
💰 비용 (무료인가?)
Strimzi Kafka Bridge | ✅ 완전 무료 (Apache 2.0) |
Confluent REST Proxy | ✅ 기본 기능은 무료, Confluent Platform 유료 옵션은 있음 |
Kafka 자체 | ✅ Apache 2.0 (무료) |
🧭 사용 시 고려사항
인증/보안 | TLS, Token 인증을 추가 설정해야 안전함 |
처리량 | 고속 대량 처리에는 Kafka 클라이언트가 더 효율적 |
운영 방식 | 프록시는 Stateless, Scale-out 쉬움 (HPA 적용 가능) |
응답 처리 | Kafka는 본래 비동기 → 응답은 수신 확인(ack) 수준만 가능 |
🚪 기본 엔드포인트
기본 주소 (예):
http://<bridge-service>:8080
📬 Kafka 토픽에 메시지 전송 (produce)
🔹 POST /topics/{topicname}
Kafka에 메시지를 전송합니다.
예제
curl -X POST http://bridge-service:8080/topics/my-topic \
-H "Content-Type: application/json" \
-d '{
"records": [
{ "key": "user1", "value": { "name": "홍길동", "age": 30 } },
{ "key": "user2", "value": { "name": "김철수", "age": 25 } }
]
}'
응답 예
{
"offsets": [
{ "partition": 0, "offset": 12 },
{ "partition": 1, "offset": 5 }
]
}
📥 Kafka 토픽에서 메시지 읽기 (consume)
🔹 POST /consumers/{groupid}
Kafka consumer group을 등록합니다.
예제
curl -X POST http://bridge-service:8080/consumers/my-group \
-H "Content-Type: application/vnd.kafka.v2+json" \
-d '{
"name": "my-consumer",
"format": "json",
"auto.offset.reset": "earliest",
"auto.commit.enable": "false"
}'
응답:
{
"instance_id": "my-consumer",
"base_uri": "http://bridge-service:8080/consumers/my-group/instances/my-consumer"
}
🔹 POST /consumers/{groupid}/instances/{instance}/subscription
토픽 구독
curl -X POST http://bridge-service:8080/consumers/my-group/instances/my-consumer/subscription \
-H "Content-Type: application/vnd.kafka.v2+json" \
-d '{ "topics": ["my-topic"] }'
🔹 GET /consumers/{groupid}/instances/{instance}/records
토픽에서 메시지 읽기
curl -X GET http://bridge-service:8080/consumers/my-group/instances/my-consumer/records \
-H "Accept: application/vnd.kafka.json.v2+json"
응답 예시:
[
{
"topic": "my-topic",
"key": "user1",
"value": { "name": "홍길동", "age": 30 },
"partition": 0,
"offset": 12
}
]
🔹 DELETE /consumers/{groupid}/instances/{instance}
Consumer 인스턴스 제거
curl -X DELETE http://bridge-service:8080/consumers/my-group/instances/my-consumer
🔍 기타 유용한 명령어
🔹 GET /topics
클러스터의 모든 Kafka 토픽 리스트 조회
curl http://bridge-service:8080/topics
🔹 GET /topics/{topicname}/partitions
특정 토픽의 파티션 정보
curl http://bridge-service:8080/topics/my-topic/partitions
🧪 테스트 팁
curl | REST API 테스트에 적합 |
Postman | JSON 구조 복잡할 때 시각적으로 확인 가능 |
Kubernetes + Ingress | 외부에서 Kafka Bridge API 접근할 수 있도록 설정 |
✅ 정리: 주요 명령어 요약
동작 | HTTP Method | 경로 |
Consumer 생성 | POST | /consumers/{group} |
토픽 구독 | POST | /consumers/{group}/instances/{instance}/subscription |
메시지 읽기 | GET | /consumers/{group}/instances/{instance}/records |
Consumer 제거 | DELETE | /consumers/{group}/instances/{instance} |
메시지 전송 | POST | /topics/{topic} |
728x90
'기타' 카테고리의 다른 글
Apache APISIX 로 API Gateway(Spring Cloud Gateway) 대체 (0) | 2025.03.31 |
---|---|
RabbitMQ → Kafka 직접 치환 (0) | 2025.03.31 |
WSL(Windows Subsystem for Linux)과 VM(VirtualBox, VMware ) 리소스 효율성 (0) | 2025.03.29 |
NGINX 프록시 설정 방법 (0) | 2025.03.28 |
NSX-ALB에서의 "프록시 역할"이란? (0) | 2025.03.26 |