1

根据指南的子流支持部分,人们期望能够非常简单地配置子流:使用 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。我错过了什么吗?谢谢你的帮助。

4

1 回答 1

1

子流不能像 bean。您绝对可以将它们提取到自己的方法中,甚至private. 但是将所有东西连接在一起应该留给框架。

如果您仍然需要它们作为 bean,那么通过消息通道使用流之间的连接。

于 2017-08-25T14:09:33.133 回答