从 Spring Integration 5.5 迁移到 6.3

问题描述 投票:0回答:1

鉴于我们不再有

IntegrationComponentSpec.get()
,正确的解决方案是使用
ChannelSpec
而不是
Channel
。但我该如何将其应用到 Kotlin DSL 上呢?

在我能做之前:

    @Bean
    fun ftpMoveFileChannel(): PublishSubscribeChannel {
        return MessageChannels.publishSubscribe().get()
    }

然后使用该通道作为

integrationFlow
的第一个参数:

    @Bean
    fun moveFileFlow(): IntegrationFlow {
        return integrationFlow(ftpMoveFileChannel()) {
            handle(Sftp.outboundGateway(ftpSessionFactory(), "mv", "payload"))
            enrichHeaders {
                header("type", "download")
            }
            channel(transferredChannel())
        }
    }

但是似乎如果我想使用

MessageSpec
我必须使用
IntegrationFlow.from
:

    @Bean
    fun ftpMoveFileChannel(): PublishSubscribeChannelSpec<*> {
        return MessageChannels.publishSubscribe()
    }
    
    @Bean
    fun moveFileFlow(): IntegrationFlow {
        return IntegrationFlow.from(ftpMoveFileChannel())
            .handle(Sftp.outboundGateway(ftpSessionFactory(), "mv", "payload"))
            .enrichHeaders { spec ->
                spec.header("type", "download")
            }
            .channel(transferredChannel())
            .get()
    }

是否仍然可以使用更“Kotlin DSL 方式”?上面看起来非常像 Java 风格。

编辑:我在

spring-integration-aws
上看到,在示例中他们只是这样做:

    @Bean
    public PollableChannel s3FilesChannel() {
        return new QueueChannel();
    }

我可以将

return MessageChannels.publishSubscribe().get()
换成
PublishSubscribeChannel()
吗?

spring-integration spring-integration-dsl
1个回答
0
投票

是的,

PublishSubscribeChannel()
适合您使用。 另一种方法是在 DSL 定义中使用通道名称。

另外,建议使用bean方法参数注入,而不是调用其他bean方法:

@Bean
fun moveFileFlow(ftpMoveFileChannel: PublishSubscribeChannel): IntegrationFlow {
    return integrationFlow(ftpMoveFileChannel) {

这样你的

ftpMoveFileChannel
bean 定义仍然可以是
ChannelSpec
。由于它是
FactoryBean
,因此针对此规范生成的目标对象正确解析了注入。

© www.soinside.com 2019 - 2024. All rights reserved.