"It works!" a colleague used to shout across the office when another proof of concept was running it's first few hundred meters along the happy path, well aware that the real work started right there. This repo contains a collection of runnable and self-contained examples from various akka streams docs, tutorials, blogs and postings to provide you with exactly this feeling. See the class comment on how to run each example. These more complex examples are described below:
- HTTP file download with local cache
- Windturbine Example
- Apache Kafka WordCount
- HL7 V2 over TCP via Kafka to Websockets
These examples all deal with some kind of shared state.
Another group of examples are the *Echo
classes, which implement round trips eg HttpFileEcho.scala and WebsocketEcho.scala.
Remarks:
- Most examples are throttled so you can see from the console output what is happening.
- Some examples deliberately throw
RuntimeException
, so you can observe recovery. - No unit tests and quirky package names.
Use case with shared state:
- Process a stream of incoming messages with reoccurring TRACE_ID
- For the first message: download a .zip file from a
FileServer
and add TRACE_ID→Path to the local cache - For subsequent messages with the same TRACE_ID: fetch file from cache to avoid duplicate downloads per TRACE_ID
Class | Description |
---|---|
FileServer.scala | Local HTTP FileServer for non-idempotent file download simulation |
LocalFileCacheCaffeine.scala | Akka streams flow, which uses a local file cache implemented with caffeine to share state |
Working sample from the blog series 1-4 from Colin Breck where classic Actors are used to model shared state, life-cycle management and fault-tolerance in combination with akka-streams. Colin Breck explains these concepts and more in the 2017 Reactive Summit talk Islands in the Stream: Integrating Akka Streams and Akka Actors
Class | Description |
---|---|
SimulateWindTurbines.scala | Starts n clients which feed measurements to the server |
WindTurbineServer.scala | Start server which a accumulates measurements |
The clients communicate via websockets with the WindTurbineServer
. After a restart of SimulateWindTurbines
the clients are able to resume.
Shutting down the WindTurbineServer
results in reporting the clients that the server is not reachable.
After restarting WindTurbineServer
the clients are able to resume. Since there is no persistence, the processing just continuous.
The ubiquitous word count with additional message count (A message is a sequence of words). Start the classes in the order below and watch the console output.
Class | Description |
---|---|
KafkaServer.scala | Standalone Kafka/Zookeeper. |
WordCountProducer.scala | Client which feeds words to topic wordcount-input . Implemented with akka-streams-kafka |
WordCountKStreams.java | Client which does word and message count. Implemented with Kafka Streams DSL |
WordCountConsumer.scala | Client which consumes aggregated results from topic wordcount-output and messagecount-output . Implemented with akka-streams-kafka |
DeleteTopicUtil.scala | Utility to reset the offset |
WordCountKStreams.java
and WordCountConsumer.scala
should yield the same results.
This PoC in package alpakka.tcp_to_websockets
is some kind of Alpakka-Trophy with these stages:
Hl7TcpClient
→ Hl7Tcp2Kafka
→ KafkaServer
→ Kafka2Websocket
→ WebsocketServer
The focus is on resilience (= try not to lose messages during the restart of the stages). However, currently messages might reach the WebsocketServer
unordered (due to retry in Hl7TcpClient
) and in-flight messages may get lost.