跳到主要内容

集成图控制器

QWen Plus 中英对照 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" />
xml

以下示例展示了如何使用 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();
}

//...

}
java

请注意,为了方便起见,@EnableIntegrationGraphController 注解提供了一个 allowedOrigins 属性。这为 path 提供了 GET 访问权限。对于更复杂的情况,您可以使用标准的 Spring MVC 机制来配置 CORS 映射。