palusa2020 / kafka-akka-stream-play-demo

Demo / Exploration of Play Framework + Reactive Kafka + EventSource

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Play Framework 2.5, Reactive Kafka & EventSource demo

This demo is a single page web site which takes a form input, sends it as a json XHR request to a simple Scala Controller in Play Framework 2.5, which then pipes it to a Kafka Unified Log. A listener then receives a notification from Kafka via an event stream via Reactive Kafka and sends it immediately back to the browser as an HTML5 EventSource event.

It's also possible also send text messages to the browser and listen to the event stream from the command line using the default command line producer/consumer that comes with Kafka.

This demo does not do anything fancy with topics, partitions groups---all messages go to and from all listening clients.

Setup

Install Confluent Kafka, then:

Terminal #1

$ ./bin/zookeeper-server-start ./etc/kafka/zookeeper.properties

Terminal #2

$ ./bin/kafka-server-start ./etc/kafka/server.properties

Terminal #3

$ ./bin/schema-registry-start ./etc/schema-registry/schema-registry.properties

Launch Play

$ sbt run

Wait for the internet to download.

Open a browser at: http://localhost:9000/

Send Test Data

You can send a message directly to the browser

./bin/kafka-console-producer --broker-list localhost:9092 --topic topic1 

This should send the text to the web client.

Debugging

View all messages:

./bin/kafka-console-consumer --topic topic1 --zookeeper localhost:2181 --from-beginning

About

Demo / Exploration of Play Framework + Reactive Kafka + EventSource

License:Other


Languages

Language:Scala 81.4%Language:HTML 18.0%Language:JavaScript 0.6%