Push Notifications and Spring Cloud Bus
许多源代码存储库提供商(例如 Github、Gitlab、Gitea、Gitee、Gogs 或 Bitbucket)通过 Webhook 通知您存储库中的更改。您可以通过提供商的用户界面将 Webhook 配置为一个 URL 和一堆您感兴趣的事件。例如, Github将 POST 用于 Webhook,其中 JSON 正文包含一个提交列表和一个标头 (X-Github-Event
) 设置为 push
。如果您在 Config Server 中添加对 `spring-cloud-config-monitor`库的依赖项并激活 Spring Cloud Bus,那么 `/monitor`端点将被启用。
Many source code repository providers (such as Github, Gitlab, Gitea, Gitee, Gogs, or Bitbucket) notify you of changes in a repository through a webhook.
You can configure the webhook through the provider’s user interface as a URL and a set of events in which you are interested.
For instance, Github uses a POST to the webhook with a JSON body containing a list of commits and a header (X-Github-Event
) set to push
.
If you add a dependency on the spring-cloud-config-monitor
library and activate the Spring Cloud Bus in your Config Server, then a /monitor
endpoint is enabled.
当 webhook 激活时,Config Server 会发送 RefreshRemoteApplicationEvent
,目标是它认为可能已更改的应用程序。可以制定更改检测策略。然而,默认情况下,它会查找与应用程序名称匹配的文件中的更改(例如,foo.properties
定向到 foo
应用程序,而 application.properties
定向到所有应用程序)。当你想覆盖此行为时,要使用的策略是 PropertyPathNotificationExtractor
,该策略接受请求标头和正文作为参数,并返回已更改的文件路径列表。
When the webhook is activated, the Config Server sends a RefreshRemoteApplicationEvent
targeted at the applications it thinks might have changed.
The change detection can be strategized.
However, by default, it looks for changes in files that match the application name (for example, foo.properties
is targeted at the foo
application, while application.properties
is targeted at all applications).
The strategy to use when you want to override the behavior is PropertyPathNotificationExtractor
, which accepts the request headers and body as parameters and returns a list of file paths that changed.
默认配置可开箱即用地配合 Github、Gitlab、Gitea、Gitee、Gogs 或 Bitbucket 使用。除了来自 Github、Gitlab、Gitee 或 Bitbucket 的 JSON 通知外,你还可以通过使用 path={application}
模式的表单编码正文参数将 POST 发送到 /monitor
来触发更改通知。这样做可以向与 {application}
模式匹配的应用程序广播(该模式可以包含通配符)。
The default configuration works out of the box with Github, Gitlab, Gitea, Gitee, Gogs or Bitbucket.
In addition to the JSON notifications from Github, Gitlab, Gitee, or Bitbucket, you can trigger a change notification by POSTing to /monitor
with form-encoded body parameters in the pattern of path={application}
.
Doing so broadcasts to applications matching the {application}
pattern (which can contain wildcards).
只有当 config server 和客户端应用程序中都激活 |
The |
默认配置还会检测本地 Git 存储库中的文件系统更改。在这种情况下,将不会使用 Webhook。但是,只要您编辑配置文件,就会广播刷新。 |
The default configuration also detects filesystem changes in local git repositories. In that case, the webhook is not used. However, as soon as you edit a config file, a refresh is broadcast. |