Version Matrix

CI PublishCoveralls github Codacy Badge Maven Central

akka-stream-netty is a scala lib to adapt netty transport to akka-stream, which let us can use native transport with:

  • epoll
  • kqueue
  • unix domain socket

alpakka-unix-domain-socket would be a alternative if you only want to use unix domain socket.

Dependencies

libraryDependencies += "com.github.zhongl" %% "akka-stream-netty-all" % <latest tag>

Usage

import java.net._
import scala.concurrent.duration._
import akka.actor.ActorSystem
import akka.stream.ActorMaterializer
import akka.stream.scaladsl._
import akka.util.ByteString
import io.netty.channel.socket._
import zhongl.stream.netty._
import all._

implicit val system = ActorSystem("demo")
implicit val mat = ActorMaterializer()
implicit val ec = system.dispatcher

Netty().bindAndHandle[ServerSocketChannel](Flow[ByteString].map(identity), new InetSocketAddress("localhost", 8080)).flatMap { sb =>
  Source.repeat(ByteString("a"))
    .delay(1.seconds) 
    .via(Netty().outgoingConnection[SocketChannel](sb.localAddress))
    .runForeach(println)
    .flatMap(_ => sb.unbind())    
}

More usage information please see test cases.