|
该版本仍在开发中,尚未被视为稳定。最新稳定版请使用Spring Modulith 2.0.0! |
可生产功能
| 如果你对这里描述的应用模块检测应用自定义,除非已经存在,否则你需要把这些自定义转移到你的生产源,以确保这些功能被考虑在内。 |
Spring Modulith 支持以 Spring Boot 执行器端点的形式,公开系统架构信息,并通过捕捉指标和跟踪来观察应用模块之间的交互。 由于生产准备应用可能需要两者,激活这些功能最方便的方式是使用Spring Modulith InsightStarters,如下:
-
Maven
-
Gradle
<dependency>
<groupId>org.springframework.modulith</groupId>
<artifactId>spring-modulith-starter-insight</artifactId>
<version>2.1.0-SNAPSHOT</version>
<scope>runtime</scope>
</dependency>
dependencies {
runtimeOnly 'org.springframework.modulith:spring-modulith-starter-insight:2.1.0-SNAPSHOT'
}
这将包括执行器和可观测性支持,以及Spring Boot的执行器启动功能,用于执行器的一般支持。 注意,你仍然需要添加更多依赖,将应用连接到监控工具,如Zipkin、Wavefront等,通常通过OpenTelemetry或Brave。 更多信息请参见Spring Boot参考文档的相应部分。
应用模块执行器
应用模块结构可被暴露为Spring Boot执行器。
要启用执行器,添加Spring-模量-执行器对项目的依赖性:
-
Maven
-
Gradle
<dependency>
<groupId>org.springframework.modulith</groupId>
<artifactId>spring-modulith-actuator</artifactId>
<version>2.1.0-SNAPSHOT</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.1.0-SNAPSHOT'
}
<!-- Spring Boot actuator starter required to enable actuators in general -->
dependencies {
runtimeOnly 'org.springframework.boot:spring-boot-starter-actuator'
}
运行该应用程序将暴露模制执行器资源:
GET http://localhost:8080/actuator
{
"_links": {
"self": {
"href": "http://localhost:8080/actuator",
"templated": false
},
"health-path": {
"href": "http://localhost:8080/actuator/health/{*path}",
"templated": true
},
"health": {
"href": "http://localhost:8080/actuator/health",
"templated": false
},
"modulith": { (1)
"href": "http://localhost:8080/actuator/modulith",
"templated": false
}
}
}
| 1 | 这模制执行器资源已发布。 |
这模制资源遵循以下结构:
| 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" ]
} ]
}
}
观察应用模块
应用模块之间的交互可以被截获,生成微米级的跨度,最终形成你可以在Zipkin等工具中可视化的轨迹。 要激活仪器,请在项目中添加以下运行时依赖关系:
-
Maven
-
Gradle
<dependency>
<groupId>org.springframework.modulith</groupId>
<artifactId>spring-modulith-observability</artifactId>
<version>2.1.0-SNAPSHOT</version>
<scope>runtime</scope>
</dependency>
dependencies {
runtimeOnly 'org.springframework.modulith:spring-modulith-observability:2.1.0-SNAPSHOT'
}
| 你需要根据想导入可观测性元数据的工具配置额外的基础设施依赖。 详情请查看对应的 Spring Boot 文档,了解你的配置中应包含哪些依赖。 |
这会导致所有属于应用模块API的Spring组件被装饰成拦截调用并生成毫米级范围的界面。 以下展示了示例的召唤轨迹:
在这种情况下,触发支付会改变订单状态,进而触发订单完成事件。 这些信息被引擎异步接收,触发订单上的另一个状态变化,持续几秒钟,然后又触发顺序的最终状态变化。