Search code examples
spring-integrationspring-integration-dsl

Using multiple service activators in single application


I have multiple workflows running in same application at the moment but they eventually will run in their dedicated jvm. Looks like i can only have one service activator with one handle method provided, not able to find how to add multiple, essentially one for each independent workflow. Any documentation link or code sample is greatly appreciated.

return IntegrationFlows.from(receivedDataChannel())
    .enrichHeaders(h -> h.header("kafka_source_topic", alertsInputTopic))
    .enrichHeaders(h -> h.header("target", "MLAlgo"))
    .transform(Transformers.fromJson())
    .filter(this::shouldProcess)
    .log()
    .handle(this)
    .log()
    .get();

So This handle method works great for one workflow but i have several and each need their own dedicated handle method to do the job within that workflow. I can always do some hack to manage with one but i will like to have clean separate code. Thanks


Solution

  • Instead of using handle(this) - put the service code in a separate class, add it as a @Bean and put it in Prototype @Scope; then

    .handle("beanName")
    

    and each one will get its own copy.