Skip to main content

Stream SSE messages from Kafka


Stream SSE messages from Kafka

Get started with Zilla by deploying our Docker Compose stack. Before proceeding, you should have Docker Composeopen in new window installed.

Running this Zilla sample will fanout Hello, World from a Kafka topic acting as a SSE server

Setup SSE Kafka Proxy

Create these files, zilla.yaml, docker-compose.yaml and index.html, in the same directory.

zilla.yaml
name: SSE-example
bindings:

# Proxy service entrypoint
  north_tcp_server:
    type: tcp
    kind: server
    options:
      host: 0.0.0.0
      port: 7114
    exit: north_http_server
  north_http_server:
    type: http
    kind: server
    options:
      access-control:
        policy: cross-origin
    routes:
      - when:
          - headers:
              :scheme: http
              :authority: localhost:7114
              :path: /events
        exit: north_sse_server
      - when:
          - headers:
              :scheme: http
              :authority: localhost:7114
        exit: east_http_filesystem_mapping

# UI html file server
  east_http_filesystem_mapping:
    type: http-filesystem
    kind: proxy
    routes:
      - when:
          - path: /{path}
        with:
          path: ${params.path}
        exit: east_filesystem_server
  east_filesystem_server:
    type: filesystem
    kind: server
    options:
      location: /var/www/

# SSE Server With an exit to Kafka
  north_sse_server:
    type: sse
    kind: server
    exit: north_sse_kafka_mapping
  north_sse_kafka_mapping:
    type: sse-kafka
    kind: proxy
    routes:
      - when:
          - path: /events
        with:
          topic: events
        exit: north_kafka_cache_client

# Kafka sync layer
  north_kafka_cache_client:
    type: kafka
    kind: cache_client
    exit: south_kafka_cache_server
  south_kafka_cache_server:
    type: kafka
    kind: cache_server
    options:
      bootstrap:
        - events
    exit: south_kafka_client

# Connect to local Kafka
  south_kafka_client:
    type: kafka
    kind: client
    exit: south_tcp_client
  south_tcp_client:
    type: tcp
    kind: client
    options:
      host: ${{env.KAFKA_HOST}}
      port: ${{env.KAFKA_PORT}}
    routes:
      - when:
          - cidr: 0.0.0.0/0



















 
 
 
 
 
 































 
 
 
 
 





























Run Zilla and Kafka

docker-compose up -d
  • Open the browser

Navigate to the browser http://localhost:7114/index.htmlopen in new window.

  • Click Go

With the location input set to http://localhost:7114/events you can click the Go button to connect to the SSE server. Messages will stream in as long as you have the messenger service running in docker.The stream of messages will render on the page.

...
message: Hello, world Wed May 10 14:25:45 UTC 2023

message: Hello, world Wed May 10 14:25:40 UTC 2023

open:
  • Remove the running containers
docker-compose down

See more of what Zilla can do

Go deeper into this concept with the sse.kafka.fanoutopen in new window example.

Going Deeper

Try out the other SSE examples: