Events API
이벤트 기반 파이프라인 실행을 위한 API입니다.
개요
Events API를 통해 Kafka 토픽의 이벤트를 트리거로 파이프라인을 실행할 수 있습니다. Knative Eventing을 기반으로 서버리스 이벤트 처리를 수행합니다.
사전 요구사항
- 파이프라인에
event옵션으로 Kafka 토픽이 지정되어 있어야 합니다. - Knative Eventing 및 Kafka 소스가 클러스터에 설치되어 있어야 합니다.
엔드포인트
POST /api/v1/events/{pipeline_id}
파이프라인의 이벤트 트리거를 시작합니다.
Path Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
pipeline_id | string | Yes | 파이프라인 ID |
Query Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
pipeline_version | string | No | 특정 버전 사용 |
Response
200 OK
{
"message": "Event started successfully"
}
동작 설명
- 기존 Knative 서비스와 소스가 있으면 삭제합니다.
- 새로운 Knative 서비스를 생성합니다.
- Kafka 소스를 생성하여 지정된 토픽을 구독합니다.
- 토픽에 메시지가 도착하면 파이프라인이 실행됩니다.
Error Responses
| Status Code | Description |
|---|---|
| 500 Internal Server Error | 파이프라인에 event 옵션이 없음 |
GET /api/v1/events/{pipeline_id}
이벤트 트리거의 상태를 조회합니다.
Path Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
pipeline_id | string | Yes | 파이프라인 ID |
Response
200 OK
{
"ready": true
}
| Field | Type | Description |
|---|---|---|
ready | boolean | Knative 서비스 준비 상태 |
DELETE /api/v1/events/{pipeline_id}
이벤트 트리거를 중지하고 삭제합니다.
Path Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
pipeline_id | string | Yes | 파이프라인 ID |
Response
200 OK
{
"message": "Event deleted successfully"
}
파이프라인 설정
이벤트 트리거를 사용하려면 파이프라인 옵션에 Kafka 토픽을 지정해야 합니다.
{
"id": "pipeline-abc123",
"name": "Event Pipeline",
"options": {
"event": "my-kafka-topic"
},
"steps": [...]
}
아키텍처
┌──────────────┐ ┌─────────────────┐ ┌──────────────────┐
│ Kafka Topic │────>│ Knative Source │────>│ Knative Service │
│ (event) │ │ (KafkaSource) │ │ (Pipeline Runner)│
└──────────────┘ └─────────────────┘ └──────────────────┘
- Kafka Topic: 이벤트 메시지가 발행되는 토픽
- Knative Source: Kafka 토픽을 구독하고 이벤트를 전달
- Knative Service: 이벤트를 수신하여 파이프라인 실행
사용 예시
cURL
# 이벤트 트리거 시작
curl -X POST https://api.dhub.io/api/v1/events/pipeline-abc123 \
-H "Authorization: Bearer <access_token>"
# 이벤트 상태 조회
curl https://api.dhub.io/api/v1/events/pipeline-abc123 \
-H "Authorization: Bearer <access_token>"
# 이벤트 트리거 중지
curl -X DELETE https://api.dhub.io/api/v1/events/pipeline-abc123 \
-H "Authorization: Bearer <access_token>"
이벤트 기반 파이프라인 워크플로우
// 1. 파이프라인 생성 (event 옵션 포함)
await fetch('/api/v1/pipelines/', {
method: 'POST',
headers: {
'Authorization': `Bearer ${token}`,
'Content-Type': 'application/json'
},
body: JSON.stringify({
name: 'Order Processing',
options: {
event: 'orders-topic'
},
steps: [...]
})
});
// 2. 이벤트 트리거 시작
await fetch(`/api/v1/events/${pipelineId}`, {
method: 'POST',
headers: { 'Authorization': `Bearer ${token}` }
});
// 3. 상태 확인
const status = await fetch(`/api/v1/events/${pipelineId}`, {
headers: { 'Authorization': `Bearer ${token}` }
}).then(res => res.json());
console.log('Event ready:', status.ready);
스케일링
Knative는 트래픽에 따라 자동으로 스케일링됩니다:
- Scale to Zero: 이벤트가 없으면 인스턴스가 0으로 축소
- Auto-scaling: 이벤트 처리량에 따라 자동 확장