Apache Pulsar는 메시징과 스트리밍을 통합한 클라우드 네이티브 분산 메시지 큐 및 스트리밍 플랫폼이다. 서비스 레이어(브로커)와 스토리지 레이어(BookKeeper)를 분리한 아키텍처가 특징이다.
아키텍처
클라이언트 Producer/Consumer
↓
Pulsar Broker (상태비저장 서비스 레이어)
├─ 토픽 서빙
├─ 구독 관리
└─ 데이터 캐시 (Managed Ledger)
↓
Apache BookKeeper (스토리지 레이어)
├─ Bookie (내구성 있는 스토리지)
└─ ZooKeeper (메타데이터)
분리의 장점:
- 브로커 수평 확장 독립적
- 스토리지 용량 독립적 확장
- 즉각적인 장애 복구
python
import pulsar
# 프로듀서
client = pulsar.Client('pulsar://localhost:6650')
producer = client.create_producer('persistent://public/default/orders')
producer.send(
b'{"order_id": 1001, "amount": 99.99}',
properties={'type': 'purchase', 'region': 'kr'}
)
# 컨슈머 (구독 타입)
# Exclusive: 단일 컨슈머
# Shared: 여러 컨슈머 라운드로빈
# Failover: 메인 + 대기 컨슈머
# Key_Shared: 키 기반 특정 컨슈머
consumer = client.subscribe(
'persistent://public/default/orders',
subscription_name='order-processor',
consumer_type=pulsar.ConsumerType.Shared
)
while True:
msg = consumer.receive(timeout_millis=5000)
try:
process_order(msg.data())
consumer.acknowledge(msg)
except Exception as e:
consumer.negative_acknowledge(msg) # 재처리
Pulsar vs Kafka 비교
| 항목 | Apache Pulsar | Apache Kafka |
|---|
| 아키텍처 | 브로커/스토리지 분리 | 단일 (브로커=스토리지) |
| 멀티테넌시 | 내장 (네임스페이스) | 제한적 |
| 지역 복제 | 내장 Geo-Replication | MirrorMaker 필요 |
| 스케일 아웃 | 즉각적 | 파티션 재조정 필요 |
| 구독 타입 | 4가지 | 컨슈머 그룹 |
| 메시지 보존 | TTL 또는 크기 기반 | 세그먼트 기반 |
관련 문서