为每个域对象创建角色 [英] Creating actor per domain object

查看:99
本文介绍了为每个域对象创建角色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试使用具有 ConsistentHashingPool 的路由器来动态创建actor,以基于对象id消耗消息。在这种简单情况下,一个唯一的字符串。

I have been trying to use a router with a ConsistentHashingPool to create actors on the fly to consume messages on the basis of an object id, which in this simple case is a unique string.

我想要每个域中一个演员的集合,这似乎是一种非常简单的方法。

I want an actor per domain aggregate and this seemed like a really simple way of doing it.

但是散列似乎在做奇怪的事情,并将消息发送给已经从其他散列映射值产生的演员。

But the hashing seems to be doing odd things and sending messages to actors that have already been spawned from a different hash mapping value.

ActorSystem.ActorOf(
    Props.Create(() => new MyAggergateActor()).WithRouter(
        new ConsistentHashingPool(10)
        .WithHashMapping(o => (o as MyEvent)?.MyAggregateUniqueId ?? string.Empty)
        .WithResizer(new DefaultResizer(1, int.MaxValue))), 
    "myAggregateRouter");

还从 nrOfInstances 调整值还可以破坏事物,这意味着哈希可能仅适用于一组初始实例,并且没有产生新的参与者吗?我以为调整器应该在这里为我提供帮助?

Also tweaking values from the nrOfInstances seems to break things as well, meaning the hash maybe only works across the set of initial instances and no new actors are being spawned? I thought the resizer was supposed to help me here?

请原谅我,我只是刚刚开始使用Akka。

Please forgive any naivety, I have only just started using Akka.

推荐答案

此处的关键是了解路由器的实际功能。一致的哈希表示在给定所有可能的一致哈希值的范围内,路由器池中的每个参与者都负责处理可能性范围内的哈希范围

The key here is to understand what routers really do. Consistent hashing means, that given range of all possible consistent hash values, each of actors in router's pool is responsible for handling range of hashes from total range of possibilities.

例如:如果您的一致性哈希值可以是1-100之间的值之一,则具有10个参与者的池的一致性哈希值路由器将使用从1-10散列到第一个actor的哈希值,从11-20散列到第二个actor的哈希值,依此类推...一旦调整了池的大小,这些散列范围将针对池中的每个actor重新调整-因此在这种情况下在将池的大小调整为20个角色之后,第一个角色现在的投放范围为1-5,第二个角色为6-10,依此类推。

For example: if your consistent hash can be one of the values from the possible range of 1-100, consistent hashing router with pool of 10 actors, will delegate messages with hashes from 1-10 to first actor, 11-20 to the second one, and so on... Once you'll resize the pool, those hash ranges will be re-adjusted to each actor in the pool - so in this case after resizing pool to 20 actors, first one will now serve ranges from 1-5, second 6-10 etc.

如果您想动态地创建角色根据某些实体ID向他们发送邮件,我认为您正在寻找的是 Akka。 Cluster.Sharding

If you want to create actors on the fly and route messages to them based on some entity ID, I believe that the thing, you're looking for is Akka.Cluster.Sharding.

这篇关于为每个域对象创建角色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆