整合圖控制器
如果您的應用程式是基於Web的(或者基於帶有嵌入式Web容器的Spring Boot),並且Spring Integration HTTP或WebFlux模組(分別參見HTTP支援和WebFlux支援)存在於類路徑中,您可以使用IntegrationGraphController將IntegrationGraphServer功能公開為REST服務。為此,HTTP模組提供了@EnableIntegrationGraphController和@Configuration類註解以及<int-http:graph-controller/> XML元素。與@EnableWebMvc註解(或XML定義中的<mvc:annotation-driven/>)一起,此配置註冊了一個IntegrationGraphController @RestController,其@RequestMapping.path可以在@EnableIntegrationGraphController註解或<int-http:graph-controller/>元素上進行配置。預設路徑是/integration。
IntegrationGraphController @RestController提供以下服務:
-
@GetMapping(name = "getGraph"):用於檢索自上次IntegrationGraphServer重新整理以來Spring Integration元件的狀態。o.s.i.support.management.graph.Graph將作為REST服務的@ResponseBody返回。 -
@GetMapping(path = "/refresh", name = "refreshGraph"):用於重新整理當前Graph以獲取實際執行時狀態並將其作為REST響應返回。對於度量指標,無需重新整理圖。當檢索圖時,它們是即時提供的。如果應用程式上下文自上次檢索圖以來已被修改,則可以呼叫重新整理。在這種情況下,圖將完全重建。
您可以使用Spring Security和Spring MVC專案提供的標準配置選項和元件為IntegrationGraphController設定安全性和跨域限制。以下示例實現了這些目標:
<mvc:annotation-driven />
<mvc:cors>
<mvc:mapping path="/myIntegration/**"
allowed-origins="https://:9090"
allowed-methods="GET" />
</mvc:cors>
<security:http>
<security:intercept-url pattern="/myIntegration/**" access="ROLE_ADMIN" />
</security:http>
<int-http:graph-controller path="/myIntegration" />
以下示例展示瞭如何使用Java配置實現相同的功能:
@Configuration
@EnableWebMvc // or @EnableWebFlux
@EnableWebSecurity // or @EnableWebFluxSecurity
@EnableIntegration
@EnableIntegrationGraphController(path = "/testIntegration", allowedOrigins="https://:9090")
public class IntegrationConfiguration extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.antMatchers("/testIntegration/**").hasRole("ADMIN")
// ...
.formLogin();
}
//...
}
請注意,為了方便,@EnableIntegrationGraphController註解提供了一個allowedOrigins屬性。這提供了對path的GET訪問。為了更復雜的功能,您可以使用標準的Spring MVC機制配置CORS對映。