根据指南的子流支持部分,人们期望能够非常简单地配置子流:使用 DSL 工厂或 lambdas。
// This is modified example from the guide.
@Bean
public IntegrationFlow subscribersFlow() {
return flow -> flow
.publishSubscribeChannel(Executors.newCachedThreadPool(), s -> s
.subscribe(f -> f
.<Integer>handle((p, h) -> p / 2)
.channel(c -> c.queue("subscriber1Results")))
.subscribe(
// this.subflow1()
this.subflow2()
))
.<Integer>handle((p, h) -> p * 3)
.channel(c -> c.queue("subscriber3Results"));
}
// Attempt 1:
// Just a copy paste of the logic from above.
// Does not work, java.lang.UnsupportedOperationException
@Bean
public IntegrationFlow subflow1() {
return f -> f
.<Integer>handle((p, h) -> p * 2)
.channel(c -> c.queue("subscriber2Results"));
}
// Attempt 2:
// Using DSL factories.
// Does not work, java.lang.UnsupportedOperationException
@Bean
public IntegrationFlow subflow2() {
return IntegrationFlows.from(MessageChannels.direct())
.<Integer>handle((p, h) -> p * 2)
.channel(c -> c.queue("subscriber2Results"))
.get();
}
我在上面定义的第二次尝试中遇到了这个异常。
Caused by: java.lang.UnsupportedOperationException
at org.springframework.integration.dsl.StandardIntegrationFlow.configure(StandardIntegrationFlow.java:100)
at org.springframework.integration.dsl.PublishSubscribeSpec.subscribe(PublishSubscribeSpec.java:51)
我已经试过了spring-boot-starter-integration:2.0.0.M3
。我错过了什么吗?谢谢你的帮助。