Added more examples to akka-sample-camel

This commit is contained in:
Martin Krasser 2010-06-20 17:16:06 +02:00
parent 032a7b8faf
commit be40cf6507
4 changed files with 54 additions and 20 deletions

View file

@ -7,6 +7,6 @@ http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.akkasource.org/schema/akka
http://scalablesolutions.se/akka/akka.xsd">
<akka:active-object id="blah2" target="sample.camel.BeanImpl" timeout="1000" />
<akka:active-object id="pojo3" target="sample.camel.BeanImpl" timeout="1000" />
</beans>

View file

@ -27,14 +27,18 @@ class Boot {
CamelContextManager.context.addRoutes(new CustomRouteBuilder)
// -----------------------------------------------------------------------
// Basic example (using a supervisor for consumer actors)
// Basic example
// -----------------------------------------------------------------------
val supervisor = Supervisor(
SupervisorConfig(
RestartStrategy(OneForOne, 3, 100, List(classOf[Exception])),
Supervise(actorOf[Consumer1], LifeCycle(Permanent)) ::
Supervise(actorOf[Consumer2], LifeCycle(Permanent)) :: Nil))
actorOf[Consumer1].start
actorOf[Consumer2].start
// Alternatively, use a supervisor for these actors
//val supervisor = Supervisor(
// SupervisorConfig(
// RestartStrategy(OneForOne, 3, 100, List(classOf[Exception])),
// Supervise(actorOf[Consumer1], LifeCycle(Permanent)) ::
// Supervise(actorOf[Consumer2], LifeCycle(Permanent)) :: Nil))
// -----------------------------------------------------------------------
// Routing example

View file

@ -14,8 +14,7 @@ object ServerApplication {
//
def main(args: Array[String]) {
val camelService = CamelService.newInstance
camelService.load
val camelService = CamelService.newInstance.load
RemoteNode.start("localhost", 7777)
RemoteNode.register("remote2", actorOf[RemoteActor2].start)
}

View file

@ -2,6 +2,8 @@ package sample.camel
import org.apache.camel.impl.{DefaultCamelContext, SimpleRegistry}
import org.apache.camel.builder.RouteBuilder
import org.apache.camel.spring.spi.ApplicationContextRegistry
import org.springframework.context.support.ClassPathXmlApplicationContext
import se.scalablesolutions.akka.camel.{CamelService, CamelContextManager}
import se.scalablesolutions.akka.actor.{ActorRegistry, ActiveObject}
@ -9,7 +11,7 @@ import se.scalablesolutions.akka.actor.{ActorRegistry, ActiveObject}
/**
* @author Martin Krasser
*/
object PlainApplication {
object StandaloneApplication {
def main(args: Array[String]) {
import CamelContextManager.context
@ -20,19 +22,18 @@ object PlainApplication {
// customize CamelContext
CamelContextManager.init(new DefaultCamelContext(registry))
CamelContextManager.context.addRoutes(new PlainApplicationRoute)
CamelContextManager.context.addRoutes(new StandaloneApplicationRoute)
// start CamelService
val camelService = CamelService.newInstance
camelService.load
val camelService = CamelService.newInstance.load
// access 'externally' registered active objects
assert("hello msg1" == context.createProducerTemplate.requestBody("direct:test1", "msg1"))
assert("hello msg2" == context.createProducerTemplate.requestBody("direct:test2", "msg2"))
// 'internally' register active object (requires CamelService)
ActiveObject.newInstance(classOf[ConsumerPojo2])
// access 'externally' registered active objects with active-object component
assert("hello msg1" == context.createProducerTemplate.requestBody("direct:test1", "msg1"))
assert("hello msg2" == context.createProducerTemplate.requestBody("direct:test2", "msg2"))
// internal registration is done in background. Wait a bit ...
Thread.sleep(1000)
@ -48,13 +49,43 @@ object PlainApplication {
}
}
class PlainApplicationRoute extends RouteBuilder {
class StandaloneApplicationRoute extends RouteBuilder {
def configure = {
// routes to active objects (in SimpleRegistry)
from("direct:test1").to("active-object:pojo1?method=foo")
from("direct:test2").to("active-object:pojo2?method=foo")
}
}
object SpringApplication {
// TODO
object StandaloneSpringApplication {
def main(args: Array[String]) {
import CamelContextManager.context
// use Spring application context as active object registry
val springctx = new ClassPathXmlApplicationContext("/context-standalone.xml")
val registry = new ApplicationContextRegistry(springctx)
// customize CamelContext
CamelContextManager.init(new DefaultCamelContext(registry))
CamelContextManager.context.addRoutes(new StandaloneSpringApplicationRoute)
// start CamelService
val camelService = CamelService.newInstance.load
// access 'externally' registered active objects with active-object component
assert("hello msg3" == context.createProducerTemplate.requestBody("direct:test3", "msg3"))
// shutdown CamelService
camelService.unload
// shutdown all (internally) created actors
ActorRegistry.shutdownAll
}
}
class StandaloneSpringApplicationRoute extends RouteBuilder {
def configure = {
// routes to active object (in ApplicationContextRegistry)
from("direct:test3").to("active-object:pojo3?method=foo")
}
}