9. 推送通知和 Spring Cloud Bus

许多 source code repository 提供程序(例如 Github,Gitlab,Gitea,Gitee,Gogs 或 Bitbucket)通过 webhook 通知您 repository 中的更改。您可以通过提供程序的用户界面将 webhook 配置为您感兴趣的 URL 和一组 events。例如,Github 上使用 POST 给 webhook,其中 JSON 正文包含一个提交列表和一个设置为push的标题(X-Github-Event)。如果在spring-cloud-config-monitor library 上添加依赖项并在 Config Server 中激活 Spring Cloud Bus,则启用/monitor端点。

当 webhook 被激活时,Config Server 会发送一个RefreshRemoteApplicationEvent针对它认为可能已更改的 applications。可以制定变化检测策略。但是,默认情况下,它会查找 files 中与 application name 匹配的更改(对于 example,foo.properties的目标是foo application,而application.properties则针对所有 applications)。要覆盖行为时使用的策略是PropertyPathNotificationExtractor,它接受请求 headers 和 body 作为参数,并返回已更改的文件_path 的列表。

默认的 configuration 与 Github,Gitlab,Gitea,Gitee,Gogs 或 Bitbucket 开箱即用。除了来自 Github,Gitlab,Gitee 或 Bitbucket 的 JSON 通知之外,您还可以通过在path={name}的 pattern 中使用 form-encoded body 参数 POST 到/monitor来触发更改通知。这样做会广播到匹配{name} pattern(可以包含通配符)的 applications。

仅当在 Config Server 和 client application 中激活spring-cloud-bus时才会传输RefreshRemoteApplicationEvent

默认的 configuration 还检测本地 git repositories 中的文件系统更改。在这种情况下,不使用 webhook。但是,只要编辑配置文件,刷新就是 broadcast。