控制某种类型的活动参与者的数量



是否可以控制游戏中活跃演员的数量?简而言之,我有一个名为AuthoriseVisaPaymentActor的 actor 来处理消息VisaPaymentMessage。我有一个并行循环,它发送 10 条消息,但我正在尝试创建一些东西,允许 3 个参与者同时工作,其他 7 条消息将被阻止并等待一个参与者可用。这可能吗?我目前正在使用我认为我误解的RoundRobin设置。

var actor = sys.ActorOf(
Props.Create<AuthoriseVisaPaymentActor>().WithRouter(new RoundRobinPool(1)));
actor.Tell(new VisaPaymentMessage(curr.ToString(), 9.99M, "4444"));

要设置轮循机制池/组,您需要指定要使用的参与者路径。 这可以在您的 hocon 设置中静态完成,也可以在代码中动态完成(见下文(。 至于被阻止的邮件,Akka的邮箱已经为您做到了这一点;在处理完当前正在处理的消息之前,它不会处理任何新消息。 它只是将它们保留在队列中,直到参与者准备好处理它。

// Setup the three actors
var actor1 = sys.ActorOf(Props.Create<AuthoriseVisaPaymentActor>());
var actor2 = sys.ActorOf(Props.Create<AuthoriseVisaPaymentActor>());
var actor3 = sys.ActorOf(Props.Create<AuthoriseVisaPaymentActor>());
// Get their paths
var routees = new[] { actor1.Path.ToString(), actor2.Path.ToString(), actor3.Path.ToString() };
// Create a new actor with a router
var router = sys.ActorOf(Props.Empty.WithRouter(new RoundRobinGroup(routees)));
router.Tell(new VisaPaymentMessage(curr.ToString(), 9.99M, "4444"));

最新更新