Vivid

Actor System 配置

ActorSystemOptions 与系统级选项一览

创建 ActorSystem 时通过 vivid.ActorSystemOption 配置系统级行为,所有选项汇总在 vivid.ActorSystemOptions 中。远程通讯、指标等专题见下方链接。

配置项一览

选项说明
WithActorSystemContext系统根 context;未指定时使用 context.Background()
WithActorSystemLogger系统默认 Logger;未指定时使用 log.GetDefault()
WithActorSystemDefaultAskTimeout全局默认 Ask 超时;仅 >0 时生效,默认 1 秒
WithActorSystemStopTimeoutStop() 的最大等待时间;仅 >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,或先 NewActorSystemOptionsWithActorSystemOptions 传入:

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)、ErrorActorSystemAlreadyStoppedErrorActorSystemNotStartedErrorActorSystemStartFailed / ErrorActorSystemStopFailed。详见 错误,完整列表见 pkg.go.dev - vivid

On this page