Returns an com.thoughtworks.dsl.Dsl instance for keywords.akka.actor.ReceiveMessage in the akka.actor.typed.Behavior domain.
Returns an com.thoughtworks.dsl.Dsl instance for keywords.akka.actor.ReceiveMessage in the akka.actor.typed.Behavior domain.
Given an echoActor
that receives Ping
messages and replies corresponding Pong
messages
import com.yang_bo.dsl.keywords.akka.actor.ReceiveMessage import com.yang_bo.dsl.domains.akka.actor.typed.typedReceiveMessageDsl import akka.actor.typed._ case class Ping(message: String, response: ActorRef[Pong]) case class Pong(message: String) def echoActor: Behavior[Ping] = { while (true) { val Ping(m, replyTo) = !ReceiveMessage[Ping] replyTo ! Pong(m) } throw new Exception("Unreachable code!") }
When pinging it with "hello",
then it should reply a Pong
with the same message "hello".
import akka.actor.testkit.typed.scaladsl.ActorTestKit val testKit = ActorTestKit() try { val pinger = testKit.spawn(echoActor, "ping") val probe = testKit.createTestProbe[Pong]() pinger ! Ping("hello", probe.ref) probe.expectMessage(Pong("hello")) } finally { testKit.shutdownTestKit() }
Returns an com.thoughtworks.dsl.Dsl instance for keywords.akka.actor.ReceiveMessagePartial in the akka.actor.typed.Behavior domain.
Returns an com.thoughtworks.dsl.Dsl instance for keywords.akka.actor.ReceiveMessagePartial in the akka.actor.typed.Behavior domain.
Given an echoActor
that receives Ping
messages and replies corresponding Pong
messages
import com.yang_bo.dsl.keywords.akka.actor.ReceiveMessagePartial import com.yang_bo.dsl.domains.akka.actor.typed.typedReceiveMessagePartialDsl import akka.actor.typed._ case class Ping(message: String, response: ActorRef[Pong]) case class Pong(message: String) def echoActor: Behavior[AnyRef] = { while (true) { val Ping(m, replyTo) = !ReceiveMessagePartial[Ping] replyTo ! Pong(m) } throw new Exception("Unreachable code!") }
When pinging it with "hello",
then it should reply a Pong
with the same message "message",
and other types of messages should not be handled.
import akka.actor.testkit.typed.scaladsl.ActorTestKit val testKit = ActorTestKit() try { val pinger = testKit.spawn(echoActor, "ping") val probe = testKit.createTestProbe[Pong]() object UnhandledMessage pinger ! UnhandledMessage pinger ! Ping("hello", probe.ref) probe.expectMessage(Pong("hello")) } finally { testKit.shutdownTestKit() }
Contains the com.thoughtworks.dsl.Dsl instances in the akka.actor.typed.Behavior domain.
Author:
杨博 (Yang Bo)