Subscriptions, filters and steps
Weik.io 2026.2Send the events of an event source or a channel into another channel, filtered by header or JSON path and changed on the way with kamelet steps. Product page · Video
Watch: A subscription binds source to channel, 3:57
The video binds an event source to a channel with a subscription.
This part of the video couldn't be loaded.
On this page
To send the events of an event source into a channel, write an event subscription. When the channel has a type, the events go on to the system the channel delivers to. A subscription needs no route from you, and it has versions and a deployment in each environment, as any integration does.
Forward a source’s events#
apiVersion: weik.io/v1
kind: event-subscription
metadata: { name: files-to-invoices, project: finance }
spec:
source: invoice-files
channel: invoice-created$ weikio apply -f ./finance/events/
$ weikio deploy finance/files-to-invoices --env productionEvery event the invoice-files source brings in now also lands in invoice-created and reaches every integration that receives that channel’s events. The forwarded event gets a new ID but keeps the original’s CloudEvents type, source, subject and time.
Filter#
filter lets through only the events that match. With headers, every header you list must have the value you give.
A subscription passes on the Weikio-Source header unchanged. The header has the integration that published the event, in the form <project>/<integration>. To tell apart the events of a channel that more than one integration feeds, filter by it.
A subscription’s source can also be a channel of the project, as in this one:
apiVersion: weik.io/v1
kind: event-subscription
metadata: { name: alert-on-invoices, project: finance }
spec:
source: invoice-created
channel: invoice-alerts
filter:
headers: { Weikio-Source: finance/erp-invoice-export }invoice-created has the events that finance/erp-invoice-export publishes and the file events that files-to-invoices forwards, which keep finance/invoice-files as their source. This subscription passes on only the ERP export’s events.
With jsonPath, an event passes when the JSON path matches at least one node of its body. When you combine headers and a JSON path, an event must pass both:
spec:
source: invoice-files
channel: invoice-alerts
filter:
jsonPath: "$.lines[?(@.amount > 10000)]"The subscription leaves out an event that doesn’t pass and counts it in its log. Other subscriptions and readers of the source still get the event.
Steps#
steps changes events on the way with a list of kamelet actions between the source and the channel, as in a Camel K Pipe. Each step refers to a kamelet and sets its parameters. The kamelet comes from Camel’s catalog or from your project. The filter runs first, then the steps in order:
spec:
source: invoice-files
channel: invoice-created
filter:
jsonPath: "$.lines[?(@.amount > 10000)]"
steps:
- kamelet: json-deserialize-action
parameters: {}When a forward fails#
A subscription receives its source’s events through a durable reader. When a forward fails, the event comes again after the reader’s retry delays. After the last attempt, it goes to the environment’s dead letters.
To handle a failed forward another way, set errorHandler:
| Value | What happens |
|---|---|
log |
Writes the failure once at ERROR and counts the event as handled |
{ sink: { channel: failed- |
Sends the failed event to another channel |
{ sink: { http: https:// |
Sends the failed event to a URL |
Fan out to several destinations#
Several subscriptions can receive the events of one source. A subscription can also receive the events of a channel that another subscription fills.
The event source invoice-files brings file events in, and the subscription files-to-invoices forwards every one of them into the channel invoice-created. The integration finance/erp-invoice-export publishes its events into the same channel, so the integrations that read invoice-created get both. The subscription alert-on-invoices receives the events of invoice-created, passes on only the events whose Weikio-Source header is finance/erp-invoice-export and leaves the file events out. It forwards them to invoice-alerts, a channel with the type slack, which posts each one into a Slack channel.
Delivery and CloudEvents shows how a channel with a type delivers.
List the subscriptions#
weikio get eventsubscriptions lists each subscription’s source and channel. It also shows each subscription’s state in each environment you can read:
$ weikio get eventsubscriptions --project finance