Why Tyk Streams?
Tyk Streams adds a declarative event layer on top of the Tyk Gateway, letting you expose or consume broker topics (Kafka, NATS, RabbitMQ…) through normal HTTP channels—REST, WebSocket, Server-Sent Events—without glue code. You can manage stream definitions in three interchangeable ways:Method | When to use |
---|---|
Tyk Dashboard UI | Rapid prototyping and PoCs |
OpenAPI + x-tyk-streaming | “Everything-as-code”, safe for Git |
Tyk Operator (Kubernetes CRD) | GitOps & CI/CD pipelines |
Requirements
- Tyk Gateway ≥ 5.8 with Streams feature enabled
- Apache Kafka reachable on
localhost:9093
- (Optional) Prometheus and Jaeger if you enable the commented observability blocks
Architecture
The demo shows a classic pattern: a user request becomes an event on a bus, a worker processes it asynchronously, and the result is delivered back to the same user—without leaking data across tenants.Stream-per-responsibility pattern
Stream | Role | Input | Output |
---|---|---|---|
in | Edge entrypoint: accepts HTTP, enriches payload (user_id , job_id ), publishes to jobs and echoes to caller | HTTP | Kafka + sync response |
Worker | Background micro-service: listens to jobs , attaches result: "bar" , publishes to completed | Kafka | Kafka |
out | Edge exit point: listens to completed , drops messages not owned by caller, delivers via REST/WS/SSE | Kafka | HTTP |
Processor mapping (built-in scripting)
Streams pipelines include processors. The mapping processor embeds Bloblang so you can transform or filter messages inline:- Enrich –
in
addsuser_id
&job_id
- Augment –
Worker
adds a static field{ "result": "bar" }
- Filter –
out
callsdeleted()
for non-matching users
$tyk_context.…
) can reference query params, headers, JWT claims, or any other context variable—usable anywhere in the Streams config.
Observability (optional)
Uncomment themetrics:
and tracer:
blocks to push per-stream Prometheus metrics and Jaeger traces. Tags like stream: Worker
make end-to-end tracing trivial.
Full OpenAPI definition
Copy/paste intostreams-demo.yaml
, import via Dashboard UI, or apply with Tyk Operator:
Running the demo
- Start Kafka (e.g. docker-compose).
- Launch Tyk Gateway 5.8+ with the YAML above.
- Send an event
- Receive the result (only alice’s jobs)
- Switch transport – connect via websocket
wscat -c http://127.0.0.1:8282/stream-demo/ws-in\?user\=alice
- (Optional) Enable metrics & tracing – uncomment blocks, restart Gateway, explore in Grafana & Jaeger.