Working with Event-Driven Patterns

1. Implementing Event Streaming

PlatformStrength
KafkaHigh throughput, log replay
PulsarMulti-tenant, geo-replication
NATS JetStreamLightweight, simple
AWS KinesisManaged, shards
RedpandaKafka-compatible, no ZK

2. Configuring Message Queue Integration

Example: Gateway → Kafka (HTTP-source)

routes:
  - paths: ["/events"]
    methods: [POST]
    plugins:
      - name: kafka-upstream
        config:
          bootstrap_servers: [kafka-1:9092, kafka-2:9092]
          topic: api-events
          authentication:
            mechanism: SCRAM-SHA-512
            user: gateway
            password: ${KAFKA_PASS}
          producer_async: true
          producer_request_acks: 1

3. Using Pub/Sub Patterns

PatternDetail
Topic-basedSubscribers per topic
Content-basedFilter by message attributes
FanoutOne msg → many subscribers
Queue (point-to-point)One msg → one consumer

4. Implementing Event Routing

Route ByExample
Event typeorder.created → orders topic
TenantPer-tenant partition
PriorityHigh → fast queue
RegionGeo affinity

5. Setting Up Event Transformation

TransformPurpose
CloudEvents wrappingStandardize metadata
Envelope addingAdd trace, source
Schema mappingv1 → v2 evolution
EnrichmentLookup + inject context

6. Configuring Dead Letter Queues

SettingDetail
Max delivery attempts5
DLQ topicSame name + .dlq
Retention14 days minimum
AlertingPage on DLQ depth > 0
Replay toolMove from DLQ to main

7. Implementing Event Replay

MethodDetail
Offset resetConsumer rewinds to N
Time-basedReplay from timestamp
SelectiveFilter by event_id
New consumer groupFresh read, no interference

8. Using Event Filtering

Example: CloudEvents filter

filters:
  - prefix:
      type: com.example.order.
  - suffix:
      subject: .premium
  - exact:
      source: /us-east/payments
  - all:
    - type: order.created
    - subject.startsWith: enterprise

9. Setting Up Event Acknowledgment

ModeGuarantee
At-most-onceAuto-ack on receive (may lose)
At-least-onceAck after process (may dup)
Exactly-onceIdempotent + txns (complex)
Manual ackApp controls offset commit

10. Configuring Event Batching

SettingTrade-off
Batch sizeLarger = throughput, latency
Linger timeWait to fill batch (5-100ms)
CompressionZstd/snappy in batch
Max in-flightPipelining cap