Integration Graph Controller

如果您的应用程序是基于 Web(或在具有嵌入式 Web 容器的 Spring Boot 之上构建),并且 Spring Integration HTTP 或 WebFlux 模块(分别参见 HTTP SupportWebFlux Support)存在于类路径中,则可以使用 IntegrationGraphController`将 `IntegrationGraphServer`功能显示为 REST 服务。为此,HTTP 模块中提供了 `@EnableIntegrationGraphController`和 `@Configuration`类注释以及 `<int-http:graph-controller/>`XML 元素。此配置与 `@EnableWebMvc`注释(或 XML 定义的 `<mvc:annotation-driven/>)一起,注册了一个 IntegrationGraphController @RestController,其中可以在 @EnableIntegrationGraphController`注释或 `<int-http:graph-controller/>`元素上配置其 `@RequestMapping.path。默认路径是 /integration

If your application is web-based (or built on top of Spring Boot with an embedded web container) and the Spring Integration HTTP or WebFlux module (see HTTP Support and WebFlux Support, respectively) is present on the classpath, you can use a IntegrationGraphController to expose the IntegrationGraphServer functionality as a REST service. For this purpose, the @EnableIntegrationGraphController and @Configuration class annotations and the <int-http:graph-controller/> XML element are available in the HTTP module. Together with the @EnableWebMvc annotation (or <mvc:annotation-driven/> for XML definitions), this configuration registers an IntegrationGraphController @RestController where its @RequestMapping.path can be configured on the @EnableIntegrationGraphController annotation or <int-http:graph-controller/> element. The default path is /integration.

IntegrationGraphController @RestController 提供以下服务:

The IntegrationGraphController @RestController provides the following services:

  • @GetMapping(name = "getGraph"): To retrieve the state of the Spring Integration components since the last IntegrationGraphServer refresh. The o.s.i.support.management.graph.Graph is returned as a @ResponseBody of the REST service.

  • @GetMapping(path = "/refresh", name = "refreshGraph"): To refresh the current Graph for the actual runtime state and return it as a REST response. It is not necessary to refresh the graph for metrics. They are provided in real-time when the graph is retrieved. Refresh can be called if the application context has been modified since the graph was last retrieved. In that case, the graph is completely rebuilt.

你可以使用 Spring Security 和 Spring MVC 项目提供的标准配置选项和组件为 IntegrationGraphController 设置安全性和跨域限制。以下示例实现了这些目标:

You can set security and cross-origin restrictions for the IntegrationGraphController with the standard configuration options and components provided by the Spring Security and Spring MVC projects. The following example achieves those goals:

<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 配置执行相同操作:

The following example shows how to do the same thing with Java configuration:

@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 映射。

Note that, for convenience, the @EnableIntegrationGraphController annotation provides an allowedOrigins attribute. This provides GET access to the path. For more sophistication, you can configure the CORS mappings by using standard Spring MVC mechanisms.