处理邮箱问题及测试设计策略
1. 邮箱选择决策
在选择邮箱类型时,默认邮箱适用于所有用例,包括 BalancingPool / BalancingDispatcher ,在这种情况下,邮箱会在多个参与者之间共享。但如果不使用 BalancingPool ,邮箱通常只有一个消息消费者。
此时,可考虑使用 SingleConsumerOnlyUnboundedMailbox ,它在大多数情况下比默认邮箱更高效,但需注意测量性能变化。不过,在使用 BalancingPool / BalancingDispatcher 时不能用此邮箱,因为其队列实现是单消费者的。
操作步骤如下:
1. 在 application.conf 中定义邮箱:
akka.actor.mymailbox{
mailbox-type = "akka.dispatch.SingleConsumerOnlyUnboundedMailbox"
}
- 创建使用该邮箱的参与者:
ActorRef clusterController = system.actorOf(Props.create(MyActor.class).withMailbox("akka.actor.mymailbox"));
超级会员免费看
订阅专栏 解锁全文
3427

被折叠的 条评论
为什么被折叠?



