1
votes

I allready have an extensive system of Camel Integration Routes. The routes are defined using camel-spring xml Route Definitions. Now I would like to replace a part of a route with an Actor System.

1.x versions of Akka provided several ways to achieve this.

Akka 2.x only offers the CamelExtension object. Extensions will only be loaded once per ActorSystem, which will be managed by Akka. This Extension initializes its own Camel context and does not offer to use an allready existing Camel-Context containing routes and Endpoints.

Is there any other possibility to integrate an 2.x Actor System into an existing Camel Route?

3

3 Answers

0
votes

This is an interesting question. I have never done this, but I would suggest trying to programmatically fetch your legacy context and "pass" it to CamelExtension:

//Legacy part
val legacySpringContext = new ClassPathXmlApplicationContext("applicationContext.xml");
val legacyCamelContext = legacySpringContext.getBean(CamelContext.class);

//Akka part
val system = ActorSystem("some system")
val akkaCamel = CamelExtension(system)

The question is...could it then be this easy?

akkaCamel.context = legacyCamelContext

I honestly don't know. The good news is that if it isn't that easy then you could probably just programmatically extract the routes from legacyCamelContext and add them to akkaCamel.context via akkaCamel.context.addRoutes.

Hope that helps.

0
votes

You can use vm component to let two camel context talk to each other in the same JVM.

0
votes

You can use the ContextProvider trait to provide CamelExtension with your own CamelContext.

For instance, here's one that registers MongoDB connection bean without using Spring:

package my.akka.app

import akka.camel.ContextProvider
import akka.actor.ExtendedActorSystem
import org.apache.camel.impl.{SimpleRegistry, DefaultCamelContext}
import com.mongodb.MongoClient

class CamelContextProvider extends ContextProvider {
  override def getContext(system: ExtendedActorSystem): DefaultCamelContext = {
    val registry = new SimpleRegistry
    val mongoClient = new MongoClient("localhost", 27017)
    registry.put("localMongo", mongoClient)
    new DefaultCamelContext(registry)
  }
}

Then you just need to configure application.conf to use your provider:

akka {
  camel {
    context-provider = "my.akka.app.CamelContextProvider"
  }
}

Now the connection bean is available in the registry for use in a route:

camelContext.addRoutes(new RouteBuilder {
    "direct:start" --> "mongodb:localMongo?database=akka&collection=test&operation=save"
})

To answer the original question, you can use the approach in Vidya's answer to get get the Spring-configured CamelContext you need and provide it to the Akka CamelExtension via this method.