集成图
从版本 4.3 开始, Spring 集成提供了对应用程序的运行时对象模型的访问,该模型可以选择包括组件度量。
它以图表的形式公开,可用于可视化集成应用程序的当前状态。
这o.s.i.support.management.graph
package 包含收集、构建和渲染 Spring 集成组件的运行时状态所需的所有类Graph
对象。
这IntegrationGraphServer
应声明为 Bean 来构建、检索和刷新Graph
对象。
结果Graph
object 可以序列化为任何格式,尽管 JSON 在客户端解析和表示起来很灵活和方便。
仅具有默认组件的 Spring 集成应用程序将公开一个图形,如下所示:
{
"contentDescriptor" : {
"providerVersion" : "6.4.2",
"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 弃用了旧指标,转而使用千分尺,如 Metrics Management 中所述。 旧版指标已在版本 5.4 中删除,将不再显示在图表中。 |
在前面的示例中,图形由三个顶级元素组成。
这contentDescriptor
graph 元素包含有关提供数据的应用程序的一般信息。
这name
可以在IntegrationGraphServer
bean 或spring.application.name
application context environment 属性。
框架提供了其他属性,并允许您将类似模型与其他源区分开来。
这links
graph 元素表示节点之间的连接,来自nodes
graph 元素,因此,在源 Spring Integration 应用程序中的集成组件之间。
例如,从MessageChannel
更改为EventDrivenConsumer
与一些MessageHandler
或从AbstractReplyProducingMessageHandler
更改为MessageChannel
.
为了方便起见并让您确定链接的用途,该模型包括type
属性。
可能的类型包括:
-
input
:标识方向MessageChannel
到终端节点,inputChannel
或requestChannel
财产 -
output
:从MessageHandler
,MessageProducer
或SourcePollingChannelAdapter
到MessageChannel
通过outputChannel
或replyChannel
财产 -
error
:从MessageHandler
上PollingConsumer
或MessageProducer
或SourcePollingChannelAdapter
到MessageChannel
通过errorChannel
财产; -
discard
:从DiscardingMessageHandler
(例如MessageFilter
) 到MessageChannel
通过errorChannel
财产。 -
route
:从AbstractMappingMessageRouter
(例如HeaderValueRouter
) 到MessageChannel
. 似output
但在运行时确定。 可能是配置的 channel mapping 或动态解析的 channel。 为此,路由器通常最多只保留 100 个动态路由,但您可以通过设置dynamicChannelLimit
财产。
可视化工具可以使用此元素中的信息来呈现节点之间的连接,这些节点来自nodes
graph 元素,其中from
和to
数字表示nodeId
属性。
例如,link
元素可用于确定适当的port
在目标节点上。
下面的 “text image” 显示了类型之间的关系:
+---(discard) | +----o----+ | | | | | | (input)--o o---(output) | | | | | | +----o----+ | +---(error)
这nodes
graph 元素可能是最有趣的,因为它的元素不仅包含运行时组件及其componentType
instances 和name
值,但也可以选择包含组件公开的指标。
Node 元素包含各种属性,这些属性通常一目了然。
例如,基于表达式的组件包括expression
包含组件的主表达式字符串的属性。
要启用这些指标,请添加@EnableIntegrationManagement
更改为@Configuration
类或添加<int:management/>
元素添加到 XML 配置中。
有关完整信息,请参阅 Metrics and Management。
这nodeId
表示唯一的增量标识符,以便将一个组件与另一个组件区分开来。
它还用于links
元素来表示此组件与其他组件的关系(连接)(如果有)。
这input
和output
attributes 用于inputChannel
和outputChannel
的属性AbstractEndpoint
,MessageHandler
,SourcePollingChannelAdapter
或MessageProducerSupport
.
有关更多信息,请参阅下一节。
从版本 5.1 开始,IntegrationGraphServer
接受Function<NamedComponent, Map<String, Object>> additionalPropertiesCallback
对于IntegrationNode
对于特定的NamedComponent
.
例如,您可以公开SmartLifecycle
autoStartup
和running
属性添加到目标图中:
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;
});
Graph 运行时模型
Spring 集成组件具有不同的复杂程度。
例如,任何轮询的MessageSource
还有一个SourcePollingChannelAdapter
以及MessageChannel
定期从源数据向其发送消息。
其他组件可能是中间件请求-回复组件(例如JmsOutboundGateway
) 替换为AbstractEndpoint
要订阅(或轮询)该requestChannel
(input
) 用于消息,并使用replyChannel
(output
) 生成要向下游发送的回复消息。
同时,任何MessageProducerSupport
implementation (例如ApplicationEventListeningMessageProducer
) 包装一些源协议侦听逻辑,并将消息发送到outputChannel
.
在图中, Spring 集成组件通过使用IntegrationNode
类层次结构,您可以在o.s.i.support.management.graph
包。
例如,您可以使用ErrorCapableDiscardingMessageHandlerNode
对于AggregatingMessageHandler
(因为它有一个discardChannel
选项),并且在从PollableChannel
通过使用PollingConsumer
.
另一个例子是CompositeMessageHandlerNode
— 对于MessageHandlerChain
当订阅了SubscribableChannel
通过使用EventDrivenConsumer
.
这@MessagingGateway (请参阅 Messaging Gateway)为其每个方法提供节点,其中name 属性基于网关的 bean 名称和短方法签名。
请考虑以下网关示例: |
@MessagingGateway(defaultRequestChannel = "four")
public interface Gate {
void foo(String foo);
void foo(Integer foo);
void bar(String bar);
}
前面的网关生成类似于以下内容的节点:
{
"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
}
您可以使用这个IntegrationNode
层次结构,用于解析 Client 端的图形模型以及了解一般的 Spring 集成运行时行为。
有关更多信息,另请参阅编程提示和技巧。
版本 5.3 引入了IntegrationPattern
abstraction 和所有代表企业集成模式 (EIP) 的开箱即用组件实现此抽象并提供IntegrationPatternType
enum 值。
此信息对于目标应用程序中的某些分类逻辑非常有用,或者,如果公开到图形节点中,则 UI 可以使用此信息来确定如何绘制组件。