From bd7bd160a0c4a0398526b4bbf129b38909fe5ca7 Mon Sep 17 00:00:00 2001 From: Martin Krasser Date: Tue, 20 Jul 2010 18:48:34 +0200 Subject: [PATCH] Minor changes in akka-sample-camel --- .../src/main/scala/Actors.scala | 8 +++- .../src/main/scala/Boot.scala | 38 +++++++++---------- 2 files changed, 24 insertions(+), 22 deletions(-) diff --git a/akka-samples/akka-sample-camel/src/main/scala/Actors.scala b/akka-samples/akka-sample-camel/src/main/scala/Actors.scala index 275dc6b094..f3b50d9c6e 100644 --- a/akka-samples/akka-sample-camel/src/main/scala/Actors.scala +++ b/akka-samples/akka-sample-camel/src/main/scala/Actors.scala @@ -117,14 +117,18 @@ class HttpConsumer(producer: ActorRef) extends Actor with Consumer { def endpointUri = "jetty:http://0.0.0.0:8875/" protected def receive = { - // only keep Exchange.HTTP_PATH message header (which needed by bridge endpoint) - case msg: Message => producer forward msg.setHeaders(msg.headers(Set(Exchange.HTTP_PATH))) + case msg => producer forward msg } } class HttpProducer(transformer: ActorRef) extends Actor with Producer { def endpointUri = "jetty://http://akkasource.org/?bridgeEndpoint=true" + override protected def receiveBeforeProduce = { + // only keep Exchange.HTTP_PATH message header (which needed by bridge endpoint) + case msg: Message => msg.setHeaders(msg.headers(Set(Exchange.HTTP_PATH))) + } + override protected def receiveAfterProduce = { // do not reply but forward result to transformer case msg => transformer forward msg diff --git a/akka-samples/akka-sample-camel/src/main/scala/Boot.scala b/akka-samples/akka-sample-camel/src/main/scala/Boot.scala index 3894c24cca..b8a483b55f 100644 --- a/akka-samples/akka-sample-camel/src/main/scala/Boot.scala +++ b/akka-samples/akka-sample-camel/src/main/scala/Boot.scala @@ -16,16 +16,6 @@ import se.scalablesolutions.akka.config.ScalaConfig._ */ class Boot { - // ----------------------------------------------------------------------- - // Create CamelContext with Spring-based registry and custom route builder - // ----------------------------------------------------------------------- - - val context = new ClassPathXmlApplicationContext("/context-boot.xml", getClass) - val registry = new ApplicationContextRegistry(context) - - CamelContextManager.init(new DefaultCamelContext(registry)) - CamelContextManager.context.addRoutes(new CustomRouteBuilder) - // ----------------------------------------------------------------------- // Basic example // ----------------------------------------------------------------------- @@ -41,9 +31,17 @@ class Boot { // Supervise(actorOf[Consumer2], LifeCycle(Permanent)) :: Nil)) // ----------------------------------------------------------------------- - // Tranformer example + // Custom Camel route example // ----------------------------------------------------------------------- + // Create CamelContext and a Spring-based registry + val context = new ClassPathXmlApplicationContext("/context-boot.xml", getClass) + val registry = new ApplicationContextRegistry(context) + + // Use a custom Camel context and a custom touter builder + CamelContextManager.init(new DefaultCamelContext(registry)) + CamelContextManager.context.addRoutes(new CustomRouteBuilder) + val producer = actorOf[Producer1] val mediator = actorOf(new Transformer(producer)) val consumer = actorOf(new Consumer3(mediator)) @@ -52,12 +50,20 @@ class Boot { mediator.start consumer.start + // ----------------------------------------------------------------------- + // Non-blocking consumer-producer example (Akka homepage transformation) + // ----------------------------------------------------------------------- + + val httpTransformer = actorOf(new HttpTransformer).start + val httpProducer = actorOf(new HttpProducer(httpTransformer)).start + val httpConsumer = actorOf(new HttpConsumer(httpProducer)).start + // ----------------------------------------------------------------------- // Publish subscribe examples // ----------------------------------------------------------------------- // - // Cometd example commented out because camel-cometd is broken in Camel 2.3 + // Cometd example commented out because camel-cometd is broken since Camel 2.3 // //val cometdUri = "cometd://localhost:8111/test/abc?baseResource=file:target" @@ -79,14 +85,6 @@ class Boot { actorOf[Consumer4].start // POSTing "stop" to http://0.0.0.0:8877/camel/stop stops and unpublishes this actor actorOf[Consumer5].start // POSTing any msg to http://0.0.0.0:8877/camel/start starts and published Consumer4 again. - // ----------------------------------------------------------------------- - // Non-blocking consumer-producer example (Akka homepage transformation) - // ----------------------------------------------------------------------- - - val nbResponder = actorOf(new HttpTransformer).start - val nbProducer = actorOf(new HttpProducer(nbResponder)).start - val nbConsumer = actorOf(new HttpConsumer(nbProducer)).start - // ----------------------------------------------------------------------- // Active object example // -----------------------------------------------------------------------