2012-05-22 11:37:09 +02:00
|
|
|
package docs.camel
|
2012-04-22 17:02:06 +01:00
|
|
|
|
2012-07-12 15:00:11 +02:00
|
|
|
import akka.actor.{ Props, ActorSystem }
|
2012-06-26 00:47:06 +02:00
|
|
|
import akka.camel.CamelExtension
|
|
|
|
|
|
2012-07-22 21:40:09 +02:00
|
|
|
import language.postfixOps
|
2012-07-25 20:11:18 +02:00
|
|
|
import akka.util.Timeout
|
2012-07-22 21:40:09 +02:00
|
|
|
|
2012-05-02 21:13:52 +01:00
|
|
|
object Introduction {
|
2012-06-28 15:33:49 +02:00
|
|
|
def foo = {
|
2012-04-24 13:48:13 +02:00
|
|
|
//#Consumer-mina
|
|
|
|
|
import akka.camel.{ CamelMessage, Consumer }
|
|
|
|
|
|
2012-06-26 00:47:06 +02:00
|
|
|
class MyEndpoint extends Consumer {
|
2012-04-24 13:48:13 +02:00
|
|
|
def endpointUri = "mina:tcp://localhost:6200?textline=true"
|
|
|
|
|
|
|
|
|
|
def receive = {
|
|
|
|
|
case msg: CamelMessage ⇒ { /* ... */ }
|
|
|
|
|
case _ ⇒ { /* ... */ }
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// start and expose actor via tcp
|
|
|
|
|
import akka.actor.{ ActorSystem, Props }
|
|
|
|
|
|
2012-06-26 00:47:06 +02:00
|
|
|
val system = ActorSystem("some-system")
|
|
|
|
|
val mina = system.actorOf(Props[MyEndpoint])
|
2012-04-24 13:48:13 +02:00
|
|
|
//#Consumer-mina
|
2012-04-22 17:02:06 +01:00
|
|
|
}
|
2012-06-28 15:33:49 +02:00
|
|
|
def bar = {
|
2012-04-24 13:48:13 +02:00
|
|
|
//#Consumer
|
|
|
|
|
import akka.camel.{ CamelMessage, Consumer }
|
|
|
|
|
|
2012-06-26 00:47:06 +02:00
|
|
|
class MyEndpoint extends Consumer {
|
2012-04-24 13:48:13 +02:00
|
|
|
def endpointUri = "jetty:http://localhost:8877/example"
|
|
|
|
|
|
|
|
|
|
def receive = {
|
|
|
|
|
case msg: CamelMessage ⇒ { /* ... */ }
|
|
|
|
|
case _ ⇒ { /* ... */ }
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//#Consumer
|
2012-04-22 17:02:06 +01:00
|
|
|
}
|
2012-06-28 15:33:49 +02:00
|
|
|
def baz = {
|
2012-04-24 13:48:13 +02:00
|
|
|
//#Producer
|
|
|
|
|
import akka.actor.Actor
|
|
|
|
|
import akka.camel.{ Producer, Oneway }
|
2012-05-02 21:13:52 +01:00
|
|
|
import akka.actor.{ ActorSystem, Props }
|
2012-04-24 13:48:13 +02:00
|
|
|
|
2012-05-02 21:13:52 +01:00
|
|
|
class Orders extends Actor with Producer with Oneway {
|
|
|
|
|
def endpointUri = "jms:queue:Orders"
|
2012-04-24 13:48:13 +02:00
|
|
|
}
|
2012-05-02 21:13:52 +01:00
|
|
|
|
2012-06-26 00:47:06 +02:00
|
|
|
val sys = ActorSystem("some-system")
|
2012-05-02 21:13:52 +01:00
|
|
|
val orders = sys.actorOf(Props[Orders])
|
|
|
|
|
|
|
|
|
|
orders ! <order amount="100" currency="PLN" itemId="12345"/>
|
2012-04-24 13:48:13 +02:00
|
|
|
//#Producer
|
|
|
|
|
}
|
2012-06-26 00:47:06 +02:00
|
|
|
{
|
|
|
|
|
//#CamelExtension
|
|
|
|
|
val system = ActorSystem("some-system")
|
|
|
|
|
val camel = CamelExtension(system)
|
|
|
|
|
val camelContext = camel.context
|
|
|
|
|
val producerTemplate = camel.template
|
|
|
|
|
|
|
|
|
|
//#CamelExtension
|
|
|
|
|
}
|
|
|
|
|
{
|
|
|
|
|
//#CamelExtensionAddComponent
|
|
|
|
|
// import org.apache.activemq.camel.component.ActiveMQComponent
|
|
|
|
|
val system = ActorSystem("some-system")
|
|
|
|
|
val camel = CamelExtension(system)
|
|
|
|
|
val camelContext = camel.context
|
2012-10-01 20:35:19 +02:00
|
|
|
// camelContext.addComponent("activemq", ActiveMQComponent.activeMQComponent(
|
|
|
|
|
// "vm://localhost?broker.persistent=false"))
|
2012-06-26 00:47:06 +02:00
|
|
|
//#CamelExtensionAddComponent
|
|
|
|
|
}
|
|
|
|
|
{
|
|
|
|
|
//#CamelActivation
|
|
|
|
|
import akka.camel.{ CamelMessage, Consumer }
|
2012-07-22 21:40:09 +02:00
|
|
|
import scala.concurrent.util.duration._
|
2012-06-26 00:47:06 +02:00
|
|
|
|
|
|
|
|
class MyEndpoint extends Consumer {
|
|
|
|
|
def endpointUri = "mina:tcp://localhost:6200?textline=true"
|
|
|
|
|
|
|
|
|
|
def receive = {
|
|
|
|
|
case msg: CamelMessage ⇒ { /* ... */ }
|
|
|
|
|
case _ ⇒ { /* ... */ }
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
val system = ActorSystem("some-system")
|
|
|
|
|
val camel = CamelExtension(system)
|
|
|
|
|
val actorRef = system.actorOf(Props[MyEndpoint])
|
|
|
|
|
// get a future reference to the activation of the endpoint of the Consumer Actor
|
2012-10-01 20:35:19 +02:00
|
|
|
val activationFuture = camel.activationFutureFor(actorRef)(timeout = 10 seconds,
|
|
|
|
|
executor = system.dispatcher)
|
2012-06-26 00:47:06 +02:00
|
|
|
//#CamelActivation
|
|
|
|
|
//#CamelDeactivation
|
|
|
|
|
system.stop(actorRef)
|
|
|
|
|
// get a future reference to the deactivation of the endpoint of the Consumer Actor
|
2012-10-01 20:35:19 +02:00
|
|
|
val deactivationFuture = camel.deactivationFutureFor(actorRef)(timeout = 10 seconds,
|
|
|
|
|
executor = system.dispatcher)
|
2012-06-26 00:47:06 +02:00
|
|
|
//#CamelDeactivation
|
|
|
|
|
}
|
|
|
|
|
|
2012-04-24 13:48:13 +02:00
|
|
|
}
|