|
对于最新稳定版本,请使用 Spring Integration 7.0.0! |
消息频道
此外IntegrationFlowBuilder通过EIP方法,Java DSL提供了一个流畅的API来配置消息频道实例。
为此消息频道提供建造工厂。
以下示例展示了如何使用它:
@Bean
public PriorityChannelSpec priorityChannel() {
return MessageChannels.priority(this.mongoDbChannelMessageStore, "priorityGroup")
.interceptor(wireTap());
}
一样消息频道建造工厂可以用于通道()EIP方法IntegrationFlowBuilder连接到端点,类似于布线输入通道/输出通道在XML配置中。
默认情况下,端点有线直达频道豆名基于以下模式的例子:[IntegrationFlow.beanName].channel#[channelNameIndex].
该规则同样适用于由内联生成的无名信道消息频道架构工厂的使用情况。
然而,所有消息频道方法存在一种变体,能够识别channelId(频道识别)你可以用它来设置豆子名称消息频道实例。
这消息频道参考文献及豆名可以用作豆子方法调用。
以下示例展示了使用该条件的可能方法通道()EIP方法:
@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();
}
-
来自(“输入”)意思是“'找到并使用消息频道带有“输入”ID,或者创建一个“。 -
固定订阅者频道()产生一个实例固定订阅频道并以channelFlow.channel#0. -
channel(“queueChannel”)工作原理相同,但使用已有的queueChannel豆。 -
频道(publishSubscribe())是豆子法的参考。 -
channel(MessageChannels.executor(“executorChannel”, this.taskExecutor))是IntegrationFlowBuilder这暴露了IntegrationComponentSpec前往执行者频道并将其注册为执行者通道. -
通道(“输出”寄存器直达频道豆子输出只要没有带有该名称的豆子存在,就算是它的名字。
注:前述内容集成流程定义有效,且其所有通道都应用于满足桥接处理者实例。
注意使用相同的内联通道定义消息频道工厂来自不同集成流程实例。
即使DSL解析器将不存在的对象注册为豆子,也无法判定相同的对象(消息频道)来自不同的集成流程器皿。
以下例子是错误的: |
@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对于该通道,并使用其Beans方法,来自不同的集成流程实例。