Actor System 配置
ActorSystemOptions 与系统级选项一览
创建 ActorSystem 时通过 vivid.ActorSystemOption 配置系统级行为,所有选项汇总在 vivid.ActorSystemOptions 中。远程通讯、指标等专题见下方链接。
配置项一览
| 选项 | 说明 |
|---|---|
| WithActorSystemContext | 系统根 context;未指定时使用 context.Background() |
| WithActorSystemLogger | 系统默认 Logger;未指定时使用 log.GetDefault() |
| WithActorSystemDefaultAskTimeout | 全局默认 Ask 超时;仅 >0 时生效,默认 1 秒 |
| WithActorSystemStopTimeout | Stop() 的最大等待时间;仅 >0 时生效,默认 1 分钟。Stop() 不传参时使用该值 |
| WithActorSystemSupervisionStrategy | 系统默认监督策略;nil 时顶层使用“停止”。详见 监督策略 |
| WithActorSystemEnableMetrics | 是否启用指标;为 true 且未设 Metrics 时使用默认实现。详见 指标 |
| WithActorSystemMetrics | 自定义指标收集器。详见 指标 |
| WithActorSystemEnableMetricsUpdatedNotify | 指标更新通知策略:<0 不推送,0 每次变更推送,>0 按间隔推送。详见 指标 |
| WithActorSystemRemoting | 启用远程通讯:bindAddr 必填,advertiseAddr 可选。详见 远程通讯 |
| WithActorSystemCodec | 远程消息编解码器;与 RegisterCustomMessage 二选一。可使用 vivid-proto 作为 Proto Codec。详见 远程通讯 |
| WithActorSystemRemotingOptions | 远程高级选项(如 ConnectionReadFailedHandler、重试策略)。详见 远程通讯 |
| WithActorSystemRemotingOption | 远程选项的链式增量配置(如 ReconnectLimit、ReconnectInitialDelay 等),可传多个 Option。详见 远程通讯 |
| WithActorSystemRemotingClusterOption | 通过 ClusterOption 列表启用并配置集群(需同时启用 Remoting)。详见 集群 |
| WithActorSystemRemotingClusterOptions | 通过 *ClusterOptions 启用并配置集群(需同时启用 Remoting)。详见 集群 |
| WithActorSystemOptions | 一次性应用整份 ActorSystemOptions |
使用方式
通过 bootstrap.NewActorSystem 直接传入 Option,或先 NewActorSystemOptions 再 WithActorSystemOptions 传入:
system := bootstrap.NewActorSystem(
vivid.WithActorSystemDefaultAskTimeout(5*time.Second),
vivid.WithActorSystemStopTimeout(2*time.Minute),
vivid.WithActorSystemRemoting("0.0.0.0:8080", "node1.example.com:8080"),
)常见错误
系统级操作可能返回预定义错误,建议用 errors.Is 判定:ErrorActorSystemAlreadyStarted(重复 Start)、ErrorActorSystemAlreadyStopped、ErrorActorSystemNotStarted、ErrorActorSystemStartFailed / ErrorActorSystemStopFailed。详见 错误,完整列表见 pkg.go.dev - vivid。