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: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
Processor mapping (built-in scripting)
Streams pipelines include processors. The mapping processor embeds Bloblang so you can transform or filter messages inline:- Enrich –
inaddsuser_id&job_id - Augment –
Workeradds a static field{ "result": "bar" } - Filter –
outcallsdeleted()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.