akka - 从无类型的演员系统创建有类型的分片区域
问题描述
我有带有无类型actor系统的akka集群。现在我必须将一个节点更改为使用类型化的 Actor 问题是:如何从非类型化的 Actor 系统创建类型化的 shardregion?基本上我需要这样的东西:
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 提供类型化分片...
解决方案
您可以使用适配器导入将 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 转换为 typed系统。为您的情况选择更好的。
推荐阅读
- sql-server - 插入虚拟行以将缺失值填充到 SQL 表中
- html - Html页面元素在使用section标签堆叠多个页面时重叠到另一个页面
- javascript - 使用来自服务器的 ajax 响应填充 div
- object-detection - 在对象检测中使用 pyttsx3 进行音频输出时帧速率降低
- tensorflow - 为什么 tf.io.read_file 无法从 pathlib.Path 对象中读取?
- google-cloud-platform - 通过谷歌云存储和负载均衡器服务反应应用程序,将任何网址映射到索引?
- node.js - npm - 在 cwd 以外的目录中运行脚本
- angular - 无法绑定到 ngModel,因为它不是输入错误的已知属性
- r - 如何对公共变量而不是整个数据进行算术平均?
- r - 当行包含的元素多于数据框中的列时,将行添加到数据框中