I use akka threads in conjunction with a reactive rabbit library to create a script that pushes some information to be shared on my local rabbitmq server.
As soon as the information is transferred to the queue, I want the program to close by itself. However, it Connectionsupports the program, and I cannot find any methods for Connectionor other examples of how to kill it. Inevitably, I must manually kill the process.
My code looks something like this:
package prototype
import akka.actor.ActorSystem
import akka.stream.FlowMaterializer
import akka.stream.scaladsl.{Sink, Source}
import akka.util.ByteString
import io.scalac.amqp.{Message, Connection}
object PopulateTodoQueue extends App {
val connection = Connection()
val message = Message(ByteString("message"))
val source = Source(List(message))
val sink = Sink(connection.publishDirectly(queue = "todo"))
implicit val actorSystem = ActorSystem()
implicit val materializer = FlowMaterializer()
(source to sink).run()
// Quick hack to wait long enough for the message to send
Thread.sleep(1000)
actorSystem.shutdown()
}
This is a snippet from my build.sbt library dependencies:
"com.typesafe.akka" %% "akka-actor" % "2.3.7",
"com.typesafe.akka" %% "akka-stream-experimental" % "0.11",
"io.scalac" %% "reactive-rabbit" % "0.2.1",
- , ? , , , , .
!