diff --git a/akka-camel/src/main/scala/CamelService.scala b/akka-camel/src/main/scala/CamelService.scala
index 033fc2d01b..22b536e383 100644
--- a/akka-camel/src/main/scala/CamelService.scala
+++ b/akka-camel/src/main/scala/CamelService.scala
@@ -9,6 +9,7 @@ import org.apache.camel.CamelContext
import se.scalablesolutions.akka.actor.Actor._
import se.scalablesolutions.akka.actor.{AspectInitRegistry, ActorRegistry}
+import se.scalablesolutions.akka.config.Config._
import se.scalablesolutions.akka.util.{Bootable, Logging}
/**
@@ -29,6 +30,28 @@ trait CamelService extends Bootable with Logging {
// add listener for AspectInit registration events
AspectInitRegistry.addListener(publishRequestor)
+ /**
+ * Starts this CamelService unless akka.camel.service is set to false.
+ */
+ abstract override def onLoad = {
+ super.onLoad
+ if (config.getBool("akka.camel.service", true)) start
+ }
+
+ /**
+ * Stops this CamelService unless akka.camel.service is set to false.
+ */
+ abstract override def onUnload = {
+ if (config.getBool("akka.camel.service", true)) stop
+ super.onUnload
+ }
+
+ @deprecated("use start() instead")
+ def load = start
+
+ @deprecated("use stop() instead")
+ def unload = stop
+
/**
* Starts this CamelService. Any started actor that is a consumer actor will be (asynchronously)
* published as Camel endpoint. Consumer actors that are started after this method returned will
@@ -37,9 +60,7 @@ trait CamelService extends Bootable with Logging {
* with TypedActor.newInstance(..) (and TypedActor.newRemoteInstance(..)
* on a remote node).
*/
- abstract override def onLoad = {
- super.onLoad
-
+ def start: CamelService = {
// Only init and start if not already done by application
if (!CamelContextManager.initialized) CamelContextManager.init
if (!CamelContextManager.started) CamelContextManager.start
@@ -50,15 +71,16 @@ trait CamelService extends Bootable with Logging {
// init publishRequestor so that buffered and future events are delivered to consumerPublisher
publishRequestor ! PublishRequestorInit(consumerPublisher)
- // Register this instance as current CamelService
+ // Register this instance as current CamelService and return it
CamelServiceManager.register(this)
+ CamelServiceManager.service
}
/**
* Stops this CamelService. All published consumer actors and typed consumer actor methods will be
* unpublished asynchronously.
*/
- abstract override def onUnload = {
+ def stop = {
// Unregister this instance as current CamelService
CamelServiceManager.unregister(this)
@@ -69,36 +91,8 @@ trait CamelService extends Bootable with Logging {
// Stop related services
consumerPublisher.stop
CamelContextManager.stop
-
- super.onUnload
}
- @deprecated("use start() instead")
- def load: CamelService = {
- onLoad
- this
- }
-
- @deprecated("use stop() instead")
- def unload = onUnload
-
- /**
- * Starts the CamelService.
- *
- * @see onLoad
- */
- def start: CamelService = {
- onLoad
- this
- }
-
- /**
- * Stops the CamelService.
- *
- * @see onUnload
- */
- def stop = onUnload
-
/**
* Sets an expectation on the number of upcoming endpoint activations and returns
* a CountDownLatch that can be used to wait for the activations to occur. Endpoint
diff --git a/config/akka-reference.conf b/config/akka-reference.conf
index ee39d9ef22..b2202fb669 100644
--- a/config/akka-reference.conf
+++ b/config/akka-reference.conf
@@ -183,4 +183,8 @@ akka {
}
}
}
+
+ camel {
+ service = on
+ }
}