Version 6

    For the M1 release of SwitchYard, the easiest way of defining a Service is via the Bean Component, which builds on the CDI bean specification (JSR 299).

     

    M1 Features and Usage

    M1 already provides some great features for defining Bean Services.  You can:

     

    1. Code the Service as a simple POJO annotated with the @Service annotation.
    2. Reference another @Service from inside your @Service implementation by using a @Reference annotation.  This feature utilises CDI for injecting the @Reference to the other @Service.  All @Reference invocation are routed through the SwitchYard Exchange mechansim.
    3. A SwitchYard <implementation.bean> configuration for configuring Bean Services into your application.
    4. Build time maven tooling to scan your application and, among other things, automatically add <implementation.bean> configurations into your applications configuration.

     

    The following is a very simple example of how to define a bean @Service in M1.  In this example we have a HelloService @Service that invokes a second Logging @Service:

     

     

    @Service(HelloService.class)
    public class HelloServiceImpl implements HelloService {
    
        @Reference
        private LoggingService logger;
    
        public void hello(String message) {
             logger.log(message);
        }
    }
    
    

     

     

    Exposing this Service in your SwitchYard application configuration is as simple as (Service binding configurations not shown here):

     

     

    <switchyard xmlns="urn:switchyard-config:switchyard:1.0" xmlns:bean="urn:switchyard-component-bean:config:1.0" >
        <composite xmlns="http://docs.oasis-open.org/ns/opencsa/sca/200912" name="m1app">
            <component name="HelloService">
                <service name="HelloService">
                    <bean:interface.java interface="com.acme.HelloService"/>
                </service>
                <reference name="LoggingService">
                    <interface.java interface="com.acme.LoggingService"/>
                </reference>
                <bean:implementation.bean class="com.acme.HelloServiceImpl"/>
            </component>
            <component name="LoggingService">
                <service name="LoggingService">
                    <bean:interface.java interface="com.acme.LoggingService"/>
                </service>
                <bean:implementation.bean class="com.acme.LoggingServiceImpl"/>
            </component>
        </composite>
    </switchyard>
    

     

     

    For a more detailed example, see the M1App quickstart provided as part of the M1 release.  For more information on how to configure SwitchYard applications in this M1 release, please see the configuration documentation.

     

    Future Work/Evolution

     

    The future evolution of this feature of SwitchYard will depend on the feedback we get from users.  That said, it seems obvious that we can leverage the fact that this feature is based on CDI.  We should be able to mix SwitchYard CDI components with other CDI component types (EJB etc), which should make for a very powerful programming model.  Imagine... seemlessly injecting EJB component references into SwitchYard components and visa versa.

     

    Let us know what ideas you have.

     

     

    More Reading

     

     

    Get the Code and Contribute

     

    Please get the Bean Component code, play with it and give us your feedback.  We use Github, so it's really easy to contribute.