对于最新的稳定版本,请使用 Spring Integration 6.5.1! |
积分图
从版本 4.3 开始,Spring Integration 提供对应用程序运行时对象模型的访问,该模型可以选择包含组件指标。
它以图形的形式公开,可用于可视化集成应用程序的当前状态。
这o.s.i.support.management.graph
package 包含收集、构建和呈现 Spring Integration 组件的运行时状态所需的所有类,作为单个树状Graph
对象。
这IntegrationGraphServer
应声明为 bean 来构建、检索和刷新Graph
对象。
由此产生的Graph
对象可以序列化为任何格式,尽管 JSON 在客户端解析和表示灵活方便。
仅具有默认组件的 Spring Integration 应用程序将公开如下图:
{
"contentDescriptor" : {
"providerVersion" : "6.3.11",
"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 版弃用了旧指标,转而使用微米表,如指标管理所述。 旧版指标已在 5.4 版中删除,将不再显示在图表中。 |
在前面的示例中,图形由三个顶级元素组成。
这contentDescriptor
graph 元素包含有关提供数据的应用程序的一般信息。
这name
可以在IntegrationGraphServer
bean 或spring.application.name
应用程序上下文环境属性。
框架提供了其他属性,可让您将类似模型与其他来源区分开来。
这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
但在运行时确定。 可能是配置的通道映射或动态解析的通道。 为此,路由器通常最多只保留 100 个动态路由,但您可以通过将dynamicChannelLimit
财产。
可视化工具可以使用来自此元素的信息来渲染节点之间的连接,从nodes
graph 元素,其中from
和to
数字表示nodeId
链接节点的属性。
例如,link
元素可用于确定适当的port
在目标节点上。
以下“文本图像”显示了类型之间的关系:
+---(discard) | +----o----+ | | | | | | (input)--o o---(output) | | | | | | +----o----+ | +---(error)
这nodes
graph 元素可能是最有趣的,因为它的元素不仅包含运行时组件及其componentType
instances 和name
值,但也可以选择包含组件公开的指标。
节点元素包含各种通常不言自明的属性。
例如,基于表达式的组件包括expression
包含组件的主表达式字符串的属性。
要启用指标,请添加@EnableIntegrationManagement
设置为@Configuration
类或添加<int:management/>
元素添加到您的 XML 配置中。
有关完整信息,请参阅指标和管理。
这nodeId
表示唯一的增量标识符,以便将一个组件与另一个组件区分开来。
它也用于links
元素来表示此组件与其他组件(如果有)的关系(连接)。
这input
和output
属性用于inputChannel
和outputChannel
属性AbstractEndpoint
,MessageHandler
,SourcePollingChannelAdapter
或MessageProducerSupport
.
有关详细信息,请参阅下一节。
从 5.1 版本开始,IntegrationGraphServer
接受Function<NamedComponent, Map<String, Object>> additionalPropertiesCallback
用于填充IntegrationNode
对于特定的NamedComponent
.
例如,您可以公开SmartLifecycle
autoStartup
和running
properties 添加到目标图中:
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;
});
图形运行时模型
Spring Integration 组件具有不同级别的复杂性。
例如,任何轮询的MessageSource
还有一个SourcePollingChannelAdapter
和MessageChannel
定期从源数据向其发送消息。
其他组件可能是中间件请求-回复组件(例如JmsOutboundGateway
) 与消耗AbstractEndpoint
订阅(或轮询)的requestChannel
(input
) 表示消息,以及replyChannel
(output
) 生成要向下游发送的回复消息。
同时,任何MessageProducerSupport
实现(例如ApplicationEventListeningMessageProducer
) 包装一些源协议监听逻辑并将消息发送到outputChannel
.
在图中,Spring Integration 组件通过使用IntegrationNode
类层次结构,您可以在o.s.i.support.management.graph
包。
例如,您可以使用ErrorCapableDiscardingMessageHandlerNode
对于AggregatingMessageHandler
(因为它有一个discardChannel
选项),并且在从PollableChannel
通过使用PollingConsumer
.
另一个例子是CompositeMessageHandlerNode
— 对于一个MessageHandlerChain
当订阅SubscribableChannel
通过使用EventDrivenConsumer
.
这@MessagingGateway (参见 消息传递网关)为其每个方法提供节点,其中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
用于在客户端解析图形模型以及了解一般 Spring Integration 运行时行为的层次结构。
另请参阅编程提示和技巧以获取更多信息。
5.3 版引入了IntegrationPattern
抽象和所有开箱即用的组件(代表企业集成模式 (EIP))实现此抽象并提供IntegrationPatternType
枚举值。
此信息对于目标应用程序中的某些分类逻辑很有用,或者,在图形节点中公开时,UI 可以使用它来确定如何绘制组件。