此版本仍在开发中,尚未被视为稳定版本。对于最新的稳定版本,请使用 Spring Integration 6.3.1Spring中文文档

此版本仍在开发中,尚未被视为稳定版本。对于最新的稳定版本,请使用 Spring Integration 6.3.1Spring中文文档

从版本 4.3 开始,Spring Integration 提供对应用程序运行时对象模型的访问,该模型可以选择包含组件指标。 它以图形的形式公开,可用于可视化集成应用程序的当前状态。 该包包含收集、构建和呈现 Spring Integration 组件的运行时状态作为单个树状对象所需的所有类。 应声明为 Bean 以构建、检索和刷新对象。 生成的对象可以序列化为任何格式,尽管 JSON 在客户端上分析和表示非常灵活且方便。 仅具有默认组件的 Spring Integration 应用程序将公开一个图形,如下所示:o.s.i.support.management.graphGraphIntegrationGraphServerGraphGraphSpring中文文档

{
  "contentDescriptor" : {
    "providerVersion" : "6.2.7-SNAPSHOT",
    "providerFormatVersion" : 1.2,
    "provider" : "spring-integration",
    "name" : "myAppName:1.0"
  },
  "nodes" : [ {
    "nodeId" : 1,
    "componentType" : "null-channel",
    "integrationPatternType" : "null_channel",
    "integrationPatternCategory" : "messaging_channel",
    "properties" : { },
    "sendTimers" : {
      "successes" : {
        "count" : 1,
        "mean" : 0.0,
        "max" : 0.0
      },
      "failures" : {
        "count" : 0,
        "mean" : 0.0,
        "max" : 0.0
      }
    },
    "receiveCounters" : {
      "successes" : 0,
      "failures" : 0
    },
    "name" : "nullChannel"
  }, {
    "nodeId" : 2,
    "componentType" : "publish-subscribe-channel",
    "integrationPatternType" : "publish_subscribe_channel",
    "integrationPatternCategory" : "messaging_channel",
    "properties" : { },
    "sendTimers" : {
      "successes" : {
        "count" : 1,
        "mean" : 7.807002,
        "max" : 7.807002
      },
      "failures" : {
        "count" : 0,
        "mean" : 0.0,
        "max" : 0.0
      }
    },
    "name" : "errorChannel"
  }, {
    "nodeId" : 3,
    "componentType" : "logging-channel-adapter",
    "integrationPatternType" : "outbound_channel_adapter",
    "integrationPatternCategory" : "messaging_endpoint",
    "properties" : { },
    "output" : null,
    "input" : "errorChannel",
    "sendTimers" : {
      "successes" : {
        "count" : 1,
        "mean" : 6.742722,
        "max" : 6.742722
      },
      "failures" : {
        "count" : 0,
        "mean" : 0.0,
        "max" : 0.0
      }
    },
    "name" : "errorLogger"
  } ],
  "links" : [ {
    "from" : 2,
    "to" : 3,
    "type" : "input"
  } ]
}
版本 5.2 弃用了旧指标,转而使用微米米,如指标管理所述。 旧指标已在 V5.4 中删除,将不再显示在图表中。

在前面的示例中,图形由三个顶级元素组成。Spring中文文档

图形元素包含有关提供数据的应用程序的常规信息。 可以在 Bean 上或在应用程序上下文环境属性中自定义。 框架提供了其他属性,可用于将相似模型与其他源区分开来。contentDescriptornameIntegrationGraphServerspring.application.nameSpring中文文档

graph 元素表示来自 graph 元素的节点之间的连接,因此也表示源 Spring Integration 应用程序中的集成组件之间的连接。 例如,从 a 到 an with some 或从 an 到 a . 为方便起见,并允许您确定链接的用途,该模型包含该属性。 可能的类型有:linksnodesMessageChannelEventDrivenConsumerMessageHandlerAbstractReplyProducingMessageHandlerMessageChanneltypeSpring中文文档

  • input:标识从终结点、 或属性的方向MessageChannelinputChannelrequestChannelSpring中文文档

  • output:从 、 或 到 通过 或 属性的方向MessageHandlerMessageProducerSourcePollingChannelAdapterMessageChanneloutputChannelreplyChannelSpring中文文档

  • error:从或或到通过物业;MessageHandlerPollingConsumerMessageProducerSourcePollingChannelAdapterMessageChannelerrorChannelSpring中文文档

  • discard:从(如)到通过属性。DiscardingMessageHandlerMessageFilterMessageChannelerrorChannelSpring中文文档

  • route: 从(如 ) 到 . 与运行时类似,但在运行时确定。 可能是配置的通道映射或动态解析的通道。 为此,路由器通常最多仅保留 100 个动态路由,但您可以通过设置属性来修改此值。AbstractMappingMessageRouterHeaderValueRouterMessageChanneloutputdynamicChannelLimitSpring中文文档

可视化工具可以使用此元素中的信息来呈现图形元素节点之间的连接,其中 和 数字表示链接节点属性中的值。 例如,该元素可用于确定目标节点上的正确性。nodesfromtonodeIdlinkportSpring中文文档

以下“文本图像”显示了类型之间的关系:Spring中文文档

              +---(discard)
              |
         +----o----+
         |         |
         |         |
         |         |
(input)--o         o---(output)
         |         |
         |         |
         |         |
         +----o----+
              |
              +---(error)

图形元素可能是最有趣的,因为它的元素不仅包含运行时组件及其实例和值,还可以选择性地包含组件公开的指标。 节点元素包含各种属性,这些属性通常是不言自明的。 例如,基于表达式的组件包括包含组件的主表达式字符串的属性。 若要启用指标,请向类添加 an 或向 XML 配置添加元素。 有关完整信息,请参阅指标和管理nodescomponentTypenameexpression@EnableIntegrationManagement@Configuration<int:management/>Spring中文文档

表示唯一的增量标识符,用于区分一个组件和另一个组件。 它还在元素中用于表示此组件与其他组件(如果有)的关系(连接)。 和 属性用于 、 、 或 的 和 属性。 有关详细信息,请参阅下一节。nodeIdlinksinputoutputinputChanneloutputChannelAbstractEndpointMessageHandlerSourcePollingChannelAdapterMessageProducerSupportSpring中文文档

从 5.1 版开始,接受 for 在特定 . 例如,可以将 和 属性公开到目标图形中:IntegrationGraphServerFunction<NamedComponent, Map<String, Object>> additionalPropertiesCallbackIntegrationNodeNamedComponentSmartLifecycleautoStartuprunningSpring中文文档

server.setAdditionalPropertiesCallback(namedComponent -> {
            Map<String, Object> properties = null;
            if (namedComponent instanceof SmartLifecycle) {
                SmartLifecycle smartLifecycle = (SmartLifecycle) namedComponent;
                properties = new HashMap<>();
                properties.put("auto-startup", smartLifecycle.isAutoStartup());
                properties.put("running", smartLifecycle.isRunning());
            }
            return properties;
        });
版本 5.2 弃用了旧指标,转而使用微米米,如指标管理所述。 旧指标已在 V5.4 中删除,将不再显示在图表中。

图形运行时模型

Spring Integration 组件具有不同级别的复杂性。 例如,任何轮询都具有 a 和 a,用于定期从源数据向其发送消息。 其他组件可能是中间件请求-应答组件(例如),其中 () 用于订阅(或轮询)消息,() 用于生成要向下游发送的回复消息。 同时,任何实现(例如 )都会包装一些源协议监听逻辑,并将消息发送到 .MessageSourceSourcePollingChannelAdapterMessageChannelJmsOutboundGatewayAbstractEndpointrequestChannelinputreplyChanneloutputMessageProducerSupportApplicationEventListeningMessageProduceroutputChannelSpring中文文档

在图中,Spring Integration 组件使用类层次结构表示,您可以在包中找到该层次结构。 例如,您可以使用 for (因为它有一个选项),并且在使用 . 另一个例子是 — for a 当使用 .IntegrationNodeo.s.i.support.management.graphErrorCapableDiscardingMessageHandlerNodeAggregatingMessageHandlerdiscardChannelPollableChannelPollingConsumerCompositeMessageHandlerNodeMessageHandlerChainSubscribableChannelEventDrivenConsumerSpring中文文档

(请参阅消息传递网关)为其每个方法提供节点,其中属性基于网关的 Bean 名称和短方法签名。 请考虑以下网关示例:@MessagingGatewayname
@MessagingGateway(defaultRequestChannel = "four")
public interface Gate {

	void foo(String foo);

	void foo(Integer foo);

	void bar(String bar);

}

前面的网关生成类似于以下内容的节点:Spring中文文档

{
  "nodeId" : 10,
  "name" : "gate.bar(class java.lang.String)",
  "stats" : null,
  "componentType" : "gateway",
  "integrationPatternType" : "gateway",
  "integrationPatternCategory" : "messaging_endpoint",
  "output" : "four",
  "errors" : null
},
{
  "nodeId" : 11,
  "name" : "gate.foo(class java.lang.String)",
  "stats" : null,
  "componentType" : "gateway",
  "integrationPatternType" : "gateway",
  "integrationPatternCategory" : "messaging_endpoint",
  "output" : "four",
  "errors" : null
},
{
  "nodeId" : 12,
  "name" : "gate.foo(class java.lang.Integer)",
  "stats" : null,
  "componentType" : "gateway",
  "integrationPatternType" : "gateway",
  "integrationPatternCategory" : "messaging_endpoint",
  "output" : "four",
  "errors" : null
}

您可以使用此层次结构在客户端解析图形模型,以及了解一般的 Spring Integration 运行时行为。 有关更多信息,另请参阅编程提示和技巧IntegrationNodeSpring中文文档

版本 5.3 引入了一个抽象,所有现成的组件(表示企业集成模式 (EIP))都实现了此抽象并提供枚举值。 此信息对于目标应用程序中的某些分类逻辑很有用,或者,在图形节点中公开时,UI 可以使用它来确定如何绘制组件。IntegrationPatternIntegrationPatternTypeSpring中文文档

(请参阅消息传递网关)为其每个方法提供节点,其中属性基于网关的 Bean 名称和短方法签名。 请考虑以下网关示例:@MessagingGatewayname