我创建了一个网关和一个轮询通知通道,网关用它来路由消息。我想要一个服务激活器从频道进行轮询并做其事。但我似乎无法掌握一些关于Spring Integration的东西。
在这种情况下,我们需要一个IntegrationFlow Bean吗?不会调用网关方法只是通过频道发送消息,服务激活器只能在有新消息时自动轮询?
ConfigurationClass:
@EnableIntegration
@Configuration
@IntegrationComponentScan
class IntegrationConfiguration {
@Bean
fun notificationChannel(): MessageChannel {
return MessageChannels.queue().get()
}
@Bean
fun integrationFlow(): IntegrationFlow {
TODO()
}
}
网关:
@MessagingGateway(defaultRequestChannel = "notificationChannel")
@Component
interface NotificationGateway {
fun sendNotification(bytes: ByteArray)
}
服务:
@Service
class NotificationService {
@ServiceActivator(inputChannel = "notificationChannel")
fun sendNotification(bytes: ByteArray) {
TODO()
}
}
我是Spring Integration的新手,因为我无法找到可理解的文档,因为我的知识水平特别是在Spring Integration DSL上。
我的主要问题可能是我现在理解IntegrationFlow Bean的使用
对于像你这样的简单用例,你确实不需要IntegrationFlow
。你现在拥有的简单的@ServiceActivator
足以处理来自notificationChannel
的消息。只有你需要的是@Poller
配置中的@ServiceActivator
,因为你的notificationChannel
是PollableChannel
,它不是可订阅的。
有关详细信息,请参阅参考手册:https://docs.spring.io/spring-integration/docs/current/reference/html/#configuration-using-poller-annotation
另外要注意doc开头的段落:https://docs.spring.io/spring-integration/docs/current/reference/html/#programming-considerations