Consuma o fluxo TCP e redirecione-o para outro Sink (com Akka Streams)

Eu tento redirecionar / encaminhar um fluxo TCP para outro dissipador com o Akka 2.4.3. O programa deve abrir um soquete do servidor, ouvir as conexões de entrada e consumir o fluxo tcp. Nosso remetente não espera / aceita respostas nossas para que nunca devolvamos nada - apenas consumimos o fluxo. Depois de enquadrar o fluxo tcp, precisamos transformar os bytes em algo mais útil e enviá-los ao Sink.

Eu tentei o seguinte até agora, mas luto especialmente com a parte de como não enviar pacotes tcp de volta ao remetente e conectar corretamente o Sink.

import scala.util.Failure
import scala.util.Success

import akka.actor.ActorSystem
import akka.event.Logging
import akka.stream.ActorMaterializer
import akka.stream.scaladsl.Sink
import akka.stream.scaladsl.Tcp
import akka.stream.scaladsl.Framing
import akka.util.ByteString
import java.nio.ByteOrder
import akka.stream.scaladsl.Flow

object TcpConsumeOnlyStreamToSink {
  implicit val system = ActorSystem("stream-system")
  private val log = Logging(system, getClass.getName)    

  //The Sink
  //In reality this is of course a real Sink doing some useful things :-)
  //The Sink accept types of "SomethingMySinkUnderstand"
  val mySink = Sink.ignore;

  def main(args: Array[String]): Unit = {
    //our sender is not interested in getting replies from us
    //so we just want to consume the tcp stream and never send back anything to the sender
    val (address, port) = ("127.0.0.1", 6000)
    server(system, address, port)
  }

  def server(system: ActorSystem, address: String, port: Int): Unit = {
    implicit val sys = system
    import system.dispatcher
    implicit val materializer = ActorMaterializer()
    val handler = Sink.foreach[Tcp.IncomingConnection] { conn =>
      println("Client connected from: " + conn.remoteAddress)

      conn handleWith Flow[ByteString]
      //this is neccessary since we use a self developed tcp wire protocol
      .via(Framing.lengthField(4, 0, 65532, ByteOrder.BIG_ENDIAN)) 
      //here we want to map the raw bytes into something our Sink understands
      .map(msg => new SomethingMySinkUnderstand(msg.utf8String))
      //here we like to connect our Sink to the Tcp Source
      .to(mySink) //<------ NOT COMPILING
    }


    val tcpSource = Tcp().bind(address, port)
    val binding = tcpSource.to(handler).run()

    binding.onComplete {
      case Success(b) =>
        println("Server started, listening on: " + b.localAddress)
      case Failure(e) =>
        println(s"Server could not bind to $address:$port: ${e.getMessage}")
        system.terminate()
    }

  }

  class SomethingMySinkUnderstand(x:String) {

  }
}

Atualização: adicione isso ao seu arquivo build.sbt para obter os deps necessários

libraryDependencies += "com.typesafe.akka" % "akka-stream_2.11" % "2.4.3"

questionAnswers(1)

yourAnswerToTheQuestion