|
此版本仍在开发中,尚不被认为是稳定的。对于最新的稳定版本,请使用 Spring Integration 6.5.1! |
积分图
从版本 4.3 开始,Spring Integration 提供对应用程序运行时对象模型的访问,该模型可以选择包含组件指标。
它以图形的形式公开,可用于可视化集成应用程序的当前状态。
这o.s.i.support.management.graphpackage 包含收集、构建和呈现 Spring Integration 组件的运行时状态所需的所有类,作为单个树状Graph对象。
这IntegrationGraphServer应声明为 bean 来构建、检索和刷新Graph对象。
由此产生的Graph对象可以序列化为任何格式,尽管 JSON 在客户端解析和表示灵活方便。
仅具有默认组件的 Spring Integration 应用程序将公开如下图:
{
"contentDescriptor" : {
"providerVersion" : "7.0.0-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 版弃用了旧指标,转而使用微米表,如指标管理所述。 旧版指标已在 5.4 版中删除,将不再显示在图表中。 |
在前面的示例中,图形由三个顶级元素组成。
这contentDescriptorgraph 元素包含有关提供数据的应用程序的一般信息。
这name可以在IntegrationGraphServerbean 或spring.application.name应用程序上下文环境属性。
框架提供了其他属性,可让您将类似模型与其他来源区分开来。
这linksgraph 元素表示节点之间的连接,来自nodesgraph 元素,因此,在源 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财产。
可视化工具可以使用来自此元素的信息来渲染节点之间的连接,从nodesgraph 元素,其中from和to数字表示nodeId链接节点的属性。
例如,link元素可用于确定适当的port在目标节点上。
以下“文本图像”显示了类型之间的关系:
+---(discard)
|
+----o----+
| |
| |
| |
(input)--o o---(output)
| |
| |
| |
+----o----+
|
+---(error)
这nodesgraph 元素可能是最有趣的,因为它的元素不仅包含运行时组件及其componentTypeinstances 和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和runningproperties 添加到目标图中:
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 可以使用它来确定如何绘制组件。