I've created a Gateway and a polling notificationChannel which the Gateway uses to route messages. I want a service activator to poll from the channel and do its thing. But I can't seem to grasp a few things about Spring Integration.
In this case would we need an IntegrationFlow Bean? Wouldn't calling the gateway method just send the message trough the channel and the service activator can just poll automatically when there is a new message?
ConfigurationClass:
@EnableIntegration
@Configuration
@IntegrationComponentScan
class IntegrationConfiguration {
@Bean
fun notificationChannel(): MessageChannel {
return MessageChannels.queue().get()
}
@Bean
fun integrationFlow(): IntegrationFlow {
TODO()
}
}
Gateway:
@MessagingGateway(defaultRequestChannel = "notificationChannel")
@Component
interface NotificationGateway {
fun sendNotification(bytes: ByteArray)
}
Service:
@Service
class NotificationService {
@ServiceActivator(inputChannel = "notificationChannel")
fun sendNotification(bytes: ByteArray) {
TODO()
}
}
I am new to Spring Integration and having a rough time since I can't find understandable documentation for my level of knowledge especially on Spring Integration DSL.
My main problem might be that I do now understand the use of the IntegrationFlow Bean
For a simple use-case like yours you indeed don't need an IntegrationFlow
. The simple @ServiceActivator
as you have now is fully enough to process messages from the notificationChannel
. Only what you need is a @Poller
in that @ServiceActivator
configuration since your notificationChannel
is a PollableChannel
one and it is not subscribable one.
See Reference Manual for more info: https://docs.spring.io/spring-integration/docs/current/reference/html/#configuration-using-poller-annotation
Also pay attention to the paragraph in the beginning of the doc: https://docs.spring.io/spring-integration/docs/current/reference/html/#programming-considerations