Skip to content

Instantly share code, notes, and snippets.

@patriknw
Created November 21, 2012 16:41
Show Gist options
  • Save patriknw/4125925 to your computer and use it in GitHub Desktop.
Save patriknw/4125925 to your computer and use it in GitHub Desktop.
Spotlight for Camel
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