生產就緒功能
| 如果您正在對應用程式模組檢測應用自定義設定,如此處所述,您需要將這些設定移至您的生產源中(如果尚未存在),以確保此處描述的功能會考慮到這些設定。 |
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 跨度。下面是一個示例呼叫跟蹤
在這種特殊情況下,觸發支付會改變訂單的狀態,然後導致訂單完成事件被觸發。這會被引擎非同步接收,該引擎會觸發訂單的另一次狀態更改,工作幾秒鐘,然後依次觸發訂單的最終狀態更改。