对于最新稳定版本,请使用 Spring Integration 7.0.0spring-doc.cadn.net.cn

消息频道

此外IntegrationFlowBuilder通过EIP方法,Java DSL提供了一个流畅的API来配置消息频道实例。 为此消息频道提供建造工厂。 以下示例展示了如何使用它:spring-doc.cadn.net.cn

@Bean
public PriorityChannelSpec priorityChannel() {
    return MessageChannels.priority(this.mongoDbChannelMessageStore, "priorityGroup")
                        .interceptor(wireTap());
}

一样消息频道建造工厂可以用于通道()EIP方法IntegrationFlowBuilder连接到端点,类似于布线输入通道/输出通道在XML配置中。 默认情况下,端点有线直达频道豆名基于以下模式的例子:[IntegrationFlow.beanName].channel#[channelNameIndex]. 该规则同样适用于由内联生成的无名信道消息频道架构工厂的使用情况。 然而,所有消息频道方法存在一种变体,能够识别channelId(频道识别)你可以用它来设置豆子名称消息频道实例。 这消息频道参考文献及豆名可以用作豆子方法调用。 以下示例展示了使用该条件的可能方法通道()EIP方法:spring-doc.cadn.net.cn

@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,或者创建一个“。spring-doc.cadn.net.cn

  • 固定订阅者频道()产生一个实例固定订阅频道并以channelFlow.channel#0.spring-doc.cadn.net.cn

  • channel(“queueChannel”)工作原理相同,但使用已有的queueChannel豆。spring-doc.cadn.net.cn

  • 频道(publishSubscribe())是豆子法的参考。spring-doc.cadn.net.cn

  • channel(MessageChannels.executor(“executorChannel”, this.taskExecutor))IntegrationFlowBuilder这暴露了IntegrationComponentSpec前往执行者频道并将其注册为执行者通道.spring-doc.cadn.net.cn

  • 通道(“输出”寄存器直达频道豆子输出只要没有带有该名称的豆子存在,就算是它的名字。spring-doc.cadn.net.cn

注:前述内容集成流程定义有效,且其所有通道都应用于满足桥接处理者实例。spring-doc.cadn.net.cn

注意使用相同的内联通道定义消息频道工厂来自不同集成流程实例。 即使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();
}

这个糟糕例子的结果是以下例外:spring-doc.cadn.net.cn

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方法,来自不同的集成流程实例。spring-doc.cadn.net.cn