.. _spring-module: #################### Spring Integration #################### Module stability: **STABLE** Akkas integration with the `Spring Framework `_ supplies the Spring way of using the Typed Actor Java API and for CamelService configuration for :ref:`camel-spring-applications`. It uses Spring's custom namespaces to create Typed Actors, supervisor hierarchies and a CamelService in a Spring environment. Contents: .. contents:: :local: To use the custom name space tags for Akka you have to add the XML schema definition to your spring configuration. It is available at `http://akka.io/akka-1.0.xsd `_. The namespace for Akka is: .. code-block:: xml xmlns:akka="http://akka.io/schema/akka" Example header for Akka Spring configuration: .. code-block:: xml - Actors ------ Actors in Java are created by extending the 'UntypedActor' class and implementing the 'onReceive' method. Example how to create Actors with the Spring framework: .. code-block:: xml Supported scopes are singleton and prototype. Dependencies and properties are set with Springs ```` element. A dependency can be either a ```` or a regular ````. Get the Actor from the Spring context: .. code-block:: java ApplicationContext context = new ClassPathXmlApplicationContext("akka-spring-config.xml"); ActorRef actorRef = (ActorRef) context.getBean("myActor"); Typed Actors ------------ Here are some examples how to create Typed Actors with the Spring framework: Creating a Typed Actor: ^^^^^^^^^^^^^^^^^^^^^^^ .. code-block:: xml Supported scopes are singleton and prototype. Dependencies and properties are set with Springs ```` element. A dependency can be either a ```` or a regular ````. Get the Typed Actor from the Spring context: .. code-block:: java ApplicationContext context = new ClassPathXmlApplicationContext("akka-spring-config.xml"); MyPojo myPojo = (MyPojo) context.getBean("myActor"); Remote Actors ------------- For details on server managed and client managed remote actors see Remote Actor documentation. Configuration for a client managed remote Actor ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ :: The default for 'managed-by' is "client", so in the above example it could be left out. Configuration for a server managed remote Actor ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Server side *********** :: If the server specified by 'host' and 'port' does not exist it will not be registered. Client side *********** :: Configuration for a client managed remote Typed Actor ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ .. code-block:: xml Configuration for a server managed remote Typed Actor ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Sever side setup **************** :: Client side setup ***************** :: Dispatchers ----------- Configuration for a Typed Actor or Untyped Actor with a custom dispatcher ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ If you don't want to use the default dispatcher you can define your own dispatcher in the spring configuration. For more information on dispatchers have a look at Dispatchers documentation. .. code-block:: xml If you want to or have to share the dispatcher between Actors you can define a dispatcher and reference it from the Typed Actor configuration: .. code-block:: xml The following dispatcher types are available in spring configuration: * executor-based-event-driven * executor-based-event-driven-work-stealing * thread-based The following queue types are configurable for dispatchers using thread pools: * bounded-linked-blocking-queue * unbounded-linked-blocking-queue * synchronous-queue * bounded-array-blocking-queue If you have set up your IDE to be XSD-aware you can easily write your configuration through auto-completion. Stopping Typed Actors and Untyped Actors ---------------------------------------- Actors with scope singleton are stopped when the application context is closed. Actors with scope prototype must be stopped by the application. Supervisor Hierarchies ---------------------- The supervisor configuration in Spring follows the declarative configuration for the Java API. Have a look at Akka's approach to fault tolerance. Example spring supervisor configuration ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ .. code-block:: xml java.io.IOException java.io.IOException java.lang.NullPointerException Get the TypedActorConfigurator from the Spring context ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ .. code-block:: java TypedActorConfigurator myConfigurator = (TypedActorConfigurator) context.getBean("my-supervisor"); MyPojo myPojo = (MyPOJO) myConfigurator.getInstance(MyPojo.class); Property Placeholders --------------------- The Akka configuration can be made available as property placeholders by using a custom property placeholder configurer for Configgy: :: Camel configuration ------------------- For details refer to the :ref:`camel-module` documentation: * CamelService configuration for :ref:`camel-spring-applications` * Access to Typed Actors :ref:`camel-typed-actors-using-spring`