I'm building an Akka application and want to expose the FSM state transitions of some actors to external consumers. (The end goal is to be able to push the state transition messages to a websocket so that they can be viewed in realtime.)
Based on the documentation, Combining dynamic stages to build a simple Publish-Subscribe service, it looks like I need to expose the Flow that represents the pub-sub channel so that it can be used by consumers and producers.
The part I'm having trouble with is attaching new Source(s) to the Flow such that each new actor that is spawned will publish its state transitions to the Source. The other issue is adding new Sinks to the Flow (in the end, this will be websockets but for testing purposes, it could be any new Sink).
First I connect a MergeHub and a BroadcastHub to form a "channel" and then create the Flow from the materialized sink and source:
val orderFlow: Flow[String, String, NotUsed] = {
val (sink, source) = MergeHub.source[String](16)
.toMat(BroadcastHub.sink(256))(Keep.both).run()
Flow.fromSinkAndSource(sink, source)
}
The question is then how can I dynamically add new producers and consumers to this Flow? Any ideas?