我正在尝试使用actor选择向actor发送消息。但它一直在死信。 这是如何创建actor的(使用激活器模板)
class PingActor extends Actor with ActorLogging {
import PingActor._
var counter = 0
val pongActor = context.actorOf(PongActor.props, "pongActor")
val tester = context.actorSelection("../pongActor") //getting the actor by name using the actorSelection
def receive = {
case Initialize =>
log.info("In PingActor - starting ping-pong")
tester.tell(PingMessage("ping"),self)//going to dead letters
tester ! PingMessage("ping")//also going to dead letters
case PongActor.PongMessage(text) =>
log.info("In PingActor - received message: {}", text)
counter += 1
if (counter == 3) context.system.shutdown()
else sender() ! PingMessage("ping")
}
}
object PingActor {
val props = Props[PingActor]
case object Initialize
case class PingMessage(text: String)
}
这是派遣演员:
found = false;
double priceFound = 0;
for (int i = 0; i < 5; i++)
{
if (order.Equals(toppings[i]))
{
found = true;
priceFound = price[i]; // store the found price
}
}
Console.WriteLine("The price of " + order + " is $" + priceFound);
为什么消息会传到死信
如何验证演员是否确实存在?
答案 0 :(得分:3)
来自akka- docs
actorSelection
只在传递消息时查找现有的actor,即在创建选择时不创建actor或验证actor的存在。
更好的选择是使用resolveOne
val timeout = 1.seconds
val tester1 = context.actorSelection("pongActor").resolveOne(timeout)
答案 1 :(得分:2)
您的行CREATE TABLE hbase_table_1(key int, value string) STORED BY 'org.apache.hadoop.hive.hbase.HBaseStorageHandler' WITH SERDEPROPERTIES ("hbase.columns.mapping" = ":key,cf1:val") TBLPROPERTIES ("hbase.table.name" = "xyz");
**FAILED: Execution Error, return code 1 from org.apache.hadoop.hive.ql.exec.DDLTask. org.apache.hadoop.hbase.HTableDescriptor.addFamily(Lorg/apache/hadoop/hbase/HColumnDescriptor;)V**
是不必要的,因为上一行将val tester = context.actorSelection("../pongActor")
设置为您需要的pongActor
。只需使用actorRef
和pongActor.tell
代替pongActor !
和tester.tell
。
至于为什么tester !
查找失败:当你在父actor中创建一个子actor时(这里actorSelection
是父,Ping
是孩子),路径到子项与父项的路径相同,并附加子项名称。因此,相对于Pong
,Ping
的路径只是“pongActor”,而不是“../ pongActor”。