生产就绪功能
| 如果您正在对应用程序模块检测应用自定义设置,如此处所述,您需要将这些设置移至您的生产源中(如果尚未存在),以确保此处描述的功能会考虑到这些设置。 |
Spring Modulith 提供支持,通过 Spring Boot actuator 端点公开您的系统架构信息,并通过捕获指标和跟踪来观察应用程序模块之间的交互。由于生产就绪的应用程序可能同时需要这两者,因此激活这些功能最便捷的方式是使用 Spring Modulith Insight starter,如下所示
-
Maven
-
Gradle
<dependency>
<groupId>org.springframework.modulith</groupId>
<artifactId>spring-modulith-starter-insight</artifactId>
<version>2.0.0</version>
<scope>runtime</scope>
</dependency>
dependencies {
runtimeOnly 'org.springframework.modulith:spring-modulith-starter-insight:2.0.0'
}
这将包括执行器和可观察性支持,以及用于执行器一般支持的 Spring Boot 执行器启动。请注意,您仍然需要添加额外的依赖项,通常通过 OpenTelemetry 或 Brave 将您的应用程序连接到您的监控工具,例如 Zipkin、Wavefront 等。更多信息请参阅 Spring Boot 参考文档的相应章节。
应用程序模块执行器
应用程序模块结构可以作为 Spring Boot 执行器公开。要启用该执行器,请将 spring-modulith-actuator 依赖项添加到项目中
-
Maven
-
Gradle
<dependency>
<groupId>org.springframework.modulith</groupId>
<artifactId>spring-modulith-actuator</artifactId>
<version>2.0.0</version>
<scope>runtime</scope>
</dependency>
<!-- Spring Boot actuator starter required to enable actuators in general -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
<version>…</version>
<scope>runtime</scope>
</dependency>
dependencies {
runtimeOnly 'org.springframework.modulith:spring-modulith-actuator:2.0.0'
}
<!-- Spring Boot actuator starter required to enable actuators in general -->
dependencies {
runtimeOnly 'org.springframework.boot:spring-boot-starter-actuator'
}
运行应用程序现在将公开一个 modulith 执行器资源
GET https://:8080/actuator
{
"_links": {
"self": {
"href": "https://:8080/actuator",
"templated": false
},
"health-path": {
"href": "https://:8080/actuator/health/{*path}",
"templated": true
},
"health": {
"href": "https://:8080/actuator/health",
"templated": false
},
"modulith": { (1)
"href": "https://:8080/actuator/modulith",
"templated": false
}
}
}
| 1 | modulith 执行器资源已发布。 |
modulith 资源遵循以下结构
| JSONPath | 描述 |
|---|---|
|
应用程序模块的技术名称。 |
|
应用程序模块的人类可读名称。 |
|
应用程序模块的基础包。 |
|
(可选)父模块的名称。详见 xref:fundamentals.adoc#modules.nested。 |
|
嵌套模块的名称(如果有)。详见 xref:fundamentals.adoc#modules.nested。 |
|
应用程序模块的所有出站依赖项 |
|
所依赖的应用程序模块的名称。对 |
|
对目标模块的依赖类型。可以是 |
一个模块布局示例如下
{
"a": {
"basePackage": "example.a",
"displayName": "A",
"dependencies": []
},
"b": {
"basePackage": "example.b",
"displayName": "B",
"dependencies": [ {
"target": "a",
"types": [ "EVENT_LISTENER", "USES_COMPONENT" ]
} ]
}
}
观察应用程序模块
应用程序模块之间的交互可以被拦截以创建 Micrometer 跨度,最终形成您可以在 Zipkin 等工具中可视化的跟踪。要激活检测,请将以下运行时依赖项添加到您的项目中
-
Maven
-
Gradle
<dependency>
<groupId>org.springframework.modulith</groupId>
<artifactId>spring-modulith-observability</artifactId>
<version>2.0.0</version>
<scope>runtime</scope>
</dependency>
dependencies {
runtimeOnly 'org.springframework.modulith:spring-modulith-observability:2.0.0'
}
| 您需要根据您想要导入可观察性元数据的工具配置额外的基础设施依赖项。有关详细信息,请查阅Spring Boot 文档中关于您的设置应包含哪些依赖项的相应部分。 |
这将导致所有作为应用程序模块 API 一部分的 Spring 组件都被一个切面装饰,该切面将拦截调用并为其创建 Micrometer 跨度。下面是一个示例调用跟踪
在这种特殊情况下,触发支付会改变订单的状态,然后导致订单完成事件被触发。这会被引擎异步接收,该引擎会触发订单的另一次状态更改,工作几秒钟,然后依次触发订单的最终状态更改。