Event Subscriptions

Connect Event Sources to Event Channels for event routing

Event Subscriptions connect Event Sources to Event Channels, enabling CloudEvent routing in your system. When a subscription is created, it sets up a NATS JetStream push consumer that forwards CloudEvents from the source’s stream to the channel’s subject.

Configuration Format

Event subscriptions are configured using YAML files:

apiVersion: weik.io/v1alpha1
kind: EventSubscription
metadata:
  name: file-webhooksite
  description: Route events from file-watch source to webhook channel
spec:
  source: file-watch-test    # Name of the EventSource
  channel: webhooksite-http  # Name of the EventChannel

Applying Configuration

Use the Weikio CLI to apply event subscription configurations:

weikio config apply filename.yaml

API Endpoints

  1. GET /eventsubscriptions/v2

    • Returns all event subscriptions
    • Requires “EventSubscription.Read” policy
  2. GET /eventsubscriptions/v2/{name}

    • Returns a specific event subscription by name
    • Requires “EventSubscription.Read” policy

How It Works

When an event subscription is configured:

  1. The subscription configuration is stored in the entity store
  2. A NATS JetStream push consumer is created:
    • Uses the source’s stream as input (eventsource-{sourceName}-stream)
    • Uses the channel’s subject as deliver subject (eventchannel.{channelName})
    • Has a durable name format: subscription-{name}-durable

Example Configuration

apiVersion: weik.io/v1alpha1
kind: EventSubscription
metadata:
  name: file-webhooksite
  description: Route events from file-watch source to webhook channel
spec:
  source: file-watch-test
  channel: webhooksite-http

This configuration:

  1. Creates a subscription named “file-webhooksite”
  2. Routes CloudEvents from the “file-watch-test” event source
  3. Sends them to the “webhooksite-http” event channel

Integration with Other Features

Event Sources

  • The source specified in the subscription must exist
  • CloudEvents are read from the source’s NATS stream
  • CloudEvents are forwarded without transformation

Event Channels

  • The channel specified in the subscription must exist
  • CloudEvents are delivered to the channel’s subject
  • The channel handles the delivery to the target system