我如何在同一个IntegrationFlows构建器中发布和使用Kafka消息



我想用spring集成做一个简单的kafka生产者/消费者,我做的方式是在两个构建器中分开,每个构建器都像bean,但我希望只做一个@bean

@Bean
fun myProducerFlow(kafkaTemplate: KafkaTemplate<*, *>): IntegrationFlow {
return IntegrationFlows.from("testChannel")
.handle(Kafka.outboundChannelAdapter(kafkaTemplate)
.topic("channel1"))
.get()
}
@Bean
fun myConsumerFlow(consumerFactory: ConsumerFactory<*, *>): IntegrationFlow {
return IntegrationFlows.from(Kafka.messageDrivenChannelAdapter(consumerFactory,"channel1"))
.handle { message -> println(message) }
.get()
}

我想要这样的东西:

@Bean
fun myFlow(kafkaTemplate: KafkaTemplate<*, *>): IntegrationFlow {
return IntegrationFlows.from("testChannel")
.handle(Kafka.outboundChannelAdapter(kafkaTemplate)
.topic("channel1"))
.channel(Kafka.messageDrivenChannelAdapter(consumerFactory,"channel1"))
.handle { message -> println(message) }
.get()
}

没有办法做到这一点;消息驱动的适配器总是启动一个流。

这是两个不同的流。使用其他方式

最新更新