Created
November 21, 2012 16:41
-
-
Save patriknw/4125925 to your computer and use it in GitHub Desktop.
Spotlight for Camel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import akka.actor.{ Actor, ActorRef, Props, ActorSystem } | |
import akka.camel.{ CamelExtension, CamelMessage, Consumer, Producer } | |
import org.apache.activemq.camel.component.ActiveMQComponent | |
object CamelDemo extends App { | |
val system = ActorSystem("CamelDemo") | |
CamelExtension(system).context.addComponent("activemq", | |
ActiveMQComponent.activeMQComponent( | |
"vm://localhost?broker.persistent=false")) | |
val httpConsumer = system.actorOf(Props[HttpConsumer], "httpConsumer") | |
val queueConsumer = system.actorOf(Props[QueueConsumer], "queueConsumer") | |
} | |
// Post to this with for example: | |
// curl -H "Content-Type: text/plain" -d "Hello" http://localhost:8875/ | |
class HttpConsumer extends Consumer { | |
def endpointUri = "jetty:http://0.0.0.0:8875/" | |
val queue = context.actorOf(Props[QueueProducer], "queueProducer") | |
def receive = { | |
case msg: CamelMessage ⇒ | |
queue forward msg | |
sender ! CamelMessage("Thanks", Map.empty) | |
} | |
} | |
// Sends messages to an ActiveMQ queue | |
class QueueProducer extends Actor with Producer { | |
def endpointUri = "activemq:queue:MyQueue" | |
override def oneway: Boolean = true | |
} | |
// Receives messages from the ActiveMQ queue | |
class QueueConsumer extends Consumer { | |
def endpointUri = "activemq:queue:MyQueue" | |
def receive = { | |
case msg: CamelMessage ⇒ | |
println("consumed: " + msg.bodyAs[String]) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment