跳到主要内容
版本:7.0.2

集成图控制器

DeepSeek V3 中英对照 Integration Graph Controller

如果你的应用程序是基于Web的(或构建在带有嵌入式Web容器的Spring Boot之上),并且Spring Integration的HTTP或WebFlux模块(分别参见HTTP支持WebFlux支持)存在于类路径中,你可以使用 IntegrationGraphControllerIntegrationGraphServer 的功能作为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="http://localhost: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="http://localhost: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 映射。