从非类型化actory系统创建类型化碎片区域

时间:2018-09-06 07:32:24

标签: akka akka-cluster akka-typed

我的akka​​群集具有未键入的actor系统。 现在我必须将一个节点更改为使用类型化actor 问题是:如何从无类型的actor系统创建有类型的碎片区域? 基本上我需要这样的东西:

 import akka.cluster.sharding.typed.scaladsl.ClusterSharding
    ClusterSharding(untypedActorSyste).sharding.spawn(
      behavior = entityId ⇒ counter(entityId, 0),
      props = Props.empty,
      typeKey = TypeKey,
      settings = ClusterShardingSettings(system),
      maxNumberOfShards = 10,
      handOffStopMessage = GoodByeCounter)

我发现的所有示例都显示了如何基于typedActorSystem来提供类型的分片...

1 个答案:

答案 0 :(得分:1)

您可以使用适配器导入将typedActorSystem转换为untypedActorSystem。

// adds support for typed actors to an untyped actor system and context
import akka.actor.typed.scaladsl.adapter._

这将toUntyped隐式扩展方法添加到键入的系统中。

val typedSystem           : ActorSystem[Any]  = ActorSystem(Behavior.empty[Any], "typed-system")
implicit val untypedSystem: actor.ActorSystem = typedSystem.toUntyped

查看Coexisting文档以获取更多详细信息,另一种方法是转换Untyped to typed系统。 选择适合您情况的更好的选择。

相关问题