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:



    public class HelloServiceImpl implements HelloService {
        private LoggingService logger;
        public void hello(String 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="" name="m1app">
            <component name="HelloService">
                <service name="HelloService">
                    < interface="com.acme.HelloService"/>
                <reference name="LoggingService">
                    < interface="com.acme.LoggingService"/>
                <bean:implementation.bean class="com.acme.HelloServiceImpl"/>
            <component name="LoggingService">
                <service name="LoggingService">
                    < interface="com.acme.LoggingService"/>
                <bean:implementation.bean class="com.acme.LoggingServiceImpl"/>



    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.