跳转到主要内容

Apollo 插件

Apollo 在 Lynx 里是一个配置中心插件,而不是简单的 HTTP Client 包装层。

Runtime 事实

项目
Go modulegithub.com/go-lynx/lynx-apollo
配置前缀lynx.apollo
Runtime 插件名apollo.config.center
公开 APIGetConfigSources()GetConfigValue(namespace, key)GetApolloConfig()GetNamespace()GetMetrics()

代码支持的能力

插件会把 Apollo 配置接入 Lynx runtime,并支持:

  • 主命名空间和附加命名空间
  • merge strategy 与 priority
  • 可选本地缓存
  • 配置变更通知
  • retry 和 circuit breaker
  • 健康检查与指标
  • 配置变更 watcher 辅助能力

所以真正重要的问题通常不是“怎么手调 Apollo”,而是“Apollo 怎样进入 runtime 配置模型”。

配置

lynx:
apollo:
app_id: "demo-app"
cluster: "default"
namespace: "application"
meta_server: "http://apollo-config:8080"
enable_cache: true
enable_notification: true
service_config:
namespace: "application"
additional_namespaces:
- "shared"
merge_strategy: "override"

官方模板实际怎么用

官方模板默认并不会启用 Apollo。当前脚手架拿 Polaris 作为控制面的示例。

这个差异很重要:

  • Apollo 是 Lynx 生态里有效的配置中心插件
  • lynx-layout 当前展示的治理启动路径是 lynx.polaris,不是 lynx.apollo
  • 所以这页应该被理解成“如何换成或补上 Apollo 配置加载”,而不是“官方模板已经这样配好了”

如何使用

典型 runtime 访问方式:

plugin := lynx.Lynx().GetPluginManager().GetPlugin("apollo.config.center")
apolloPlugin := plugin.(*apollo.PlugApollo)

value, err := apolloPlugin.GetConfigValue("application", "feature.flag")
sources, err := apolloPlugin.GetConfigSources()

实际注意点

  • 当 Apollo 需要参与应用配置加载链路时,用 GetConfigSources()
  • 当你只想按需读取单个配置项时,用 GetConfigValue()
  • 命名空间划分是真正的架构设计问题,因为 merge priority 会直接影响 runtime 行为。

相关页面