此版本仍在开发中,尚未被视为稳定版本。对于最新的稳定版本,请使用 Spring Integration 6.3.1! |
此版本仍在开发中,尚未被视为稳定版本。对于最新的稳定版本,请使用 Spring Integration 6.3.1! |
除了 with EIP 方法外,Java DSL 还提供了一个流畅的 API 来配置实例。
为此,提供了建筑厂。
以下示例演示如何使用它:IntegrationFlowBuilder
MessageChannel
MessageChannels
@Bean
public PriorityChannelSpec priorityChannel() {
return MessageChannels.priority(this.mongoDbChannelMessageStore, "priorityGroup")
.interceptor(wireTap());
}
在 EIP 方法中可以使用相同的构建器工厂 from to wire endpoint,类似于在 XML 配置中连接 / 对。
缺省情况下,端点与 Bean 名称基于以下模式的实例连接:.
此规则也适用于由内联生成器出厂使用生成的未命名通道。
但是,所有方法都有一个变体,该变体可以识别可用于设置实例的 Bean 名称。
引用 和 可用作 Bean-Method 调用。
以下示例显示了使用弹性公网IP方法的可能方法:MessageChannels
channel()
IntegrationFlowBuilder
input-channel
output-channel
DirectChannel
[IntegrationFlow.beanName].channel#[channelNameIndex]
MessageChannels
MessageChannels
channelId
MessageChannel
MessageChannel
beanName
channel()
@Bean
public QueueChannelSpec queueChannel() {
return MessageChannels.queue();
}
@Bean
public PublishSubscribeChannelSpec<?> publishSubscribe() {
return MessageChannels.publishSubscribe();
}
@Bean
public IntegrationFlow channelFlow() {
return IntegrationFlow.from("input")
.fixedSubscriberChannel()
.channel("queueChannel")
.channel(publishSubscribe())
.channel(MessageChannels.executor("executorChannel", this.taskExecutor))
.channel("output")
.get();
}
-
from("input")
意思是“'查找并使用带有”输入“ID 的 ID,或创建一个”。MessageChannel
-
fixedSubscriberChannel()
生成 的实例,并使用名称 注册它。FixedSubscriberChannel
channelFlow.channel#0
-
channel("queueChannel")
工作方式相同,但使用现有 Bean。queueChannel
-
channel(publishSubscribe())
是 Bean-method 引用。 -
channel(MessageChannels.executor("executorChannel", this.taskExecutor))
是向 公开并将其注册为 的 。IntegrationFlowBuilder
IntegrationComponentSpec
ExecutorChannel
executorChannel
-
channel("output")
注册 Bean 作为其名称,只要不存在具有此名称的 Bean。DirectChannel
output
注意:上述定义有效,其所有通道都应用于具有实例的终端节点。IntegrationFlow
BridgeHandler
请注意,通过工厂从不同实例使用相同的内联通道定义。
即使 DSL 解析器将不存在的对象注册为 Bean,它也无法从不同的容器中确定相同的对象 ()。
以下示例是错误的:MessageChannels IntegrationFlow MessageChannel IntegrationFlow |
请注意,通过工厂从不同实例使用相同的内联通道定义。
即使 DSL 解析器将不存在的对象注册为 Bean,它也无法从不同的容器中确定相同的对象 ()。
以下示例是错误的:MessageChannels IntegrationFlow MessageChannel IntegrationFlow |
@Bean
public IntegrationFlow startFlow() {
return IntegrationFlow.from("input")
.transform(...)
.channel(MessageChannels.queue("queueChannel"))
.get();
}
@Bean
public IntegrationFlow endFlow() {
return IntegrationFlow.from(MessageChannels.queue("queueChannel"))
.handle(...)
.get();
}
该错误示例的结果是以下异常:
Caused by: java.lang.IllegalStateException:
Could not register object [queueChannel] under bean name 'queueChannel':
there is already object [queueChannel] bound
at o.s.b.f.s.DefaultSingletonBeanRegistry.registerSingleton(DefaultSingletonBeanRegistry.java:129)
要使其正常工作,您需要声明该通道并从不同实例使用其 bean 方法。@Bean
IntegrationFlow