Created
August 23, 2013 10:05
-
-
Save cjwebb/6317662 to your computer and use it in GitHub Desktop.
This file contains hidden or 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._ | |
import akka.camel.{CamelExtension, CamelMessage, Consumer, Producer, Oneway} | |
import org.apache.activemq.camel.component.ActiveMQComponent | |
import org.apache.activemq.ScheduledMessage | |
case class Message(body: String) | |
class SimpleConsumer() extends Actor with Consumer { | |
def endpointUri: String = "activemq:foo.bar" | |
def receive = { | |
case msg: CamelMessage => println(msg) | |
} | |
} | |
object SimpleConsumer { | |
def create(): Props = Props[SimpleConsumer] | |
} | |
class SimpleProducer() extends Actor with Producer with Oneway { | |
def endpointUri: String = "activemq:foo.bar" | |
} | |
object SimpleProducer { | |
def create(): Props = Props[SimpleProducer] | |
} | |
object CamelTesting { | |
val host = "localhost" | |
val amqUrl = s"failover:(nio://$host:61616)?timeout=3000" | |
val actorSystem = ActorSystem("CamelTesting") | |
val system = CamelExtension(actorSystem) | |
system.context.addComponent("activemq", ActiveMQComponent.activeMQComponent(amqUrl)) | |
val simpleConsumer = actorSystem.actorOf(SimpleConsumer.create()) | |
val simpleProducer = actorSystem.actorOf(SimpleProducer.create()) | |
def main(args: Array[String]) { | |
Thread.sleep(100) | |
simpleProducer ! Message("1") | |
simpleProducer ! Message("2") | |
simpleProducer ! Message("3") | |
val delayedMessage = CamelMessage(Message("delay?"), Map(ScheduledMessage.AMQ_SCHEDULED_DELAY -> 3000)) | |
simpleProducer ! delayedMessage | |
Thread.sleep(5000) | |
actorSystem.shutdown() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment