INTRODUCTION
============

This example demonstrates three features proposed by Fusesource Fabric project :
1) Configuration of a Zookeeper registry on a Karaf instance and deployment of containers
1) Provisioning of artifacts (repositories, features, bundles, configurations) based on profiles usage
2) Implementation of an example using a service distributed based on OSGI spec - Remote Services (see Chapter 13 of document www.osgi.org/download/r4v42/r4.enterprise.pdf )


Explanation
===========

The service that we will distribute is a java POJO created using an interface

    public interface Service {

        public String messageFrom(String input);

    }

and implemented here

    public class ServiceImpl implements Service {

        @Override
        public String messageFrom(String input) {
            return "Message from distributed service to : " + input;
        }
    }

To register this service (= Interfaces) into the OSGI registry, we use the folowwing Blueprint syntax

    <blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0">

        <bean id="myService" class="org.fusesource.fabric.example.dosgi.impl.ServiceImpl"/>

        <service ref="myService" auto-export="interfaces">
            <service-properties>
                <entry key="service.exported.interfaces" value="*"/>
            </service-properties>
        </service>

    </blueprint>

During this process, Fabrix will publish information in the Zookeeper registry that we will allow another Karaf container to discover them at runtime

In another bundle, we will create a Camel route we will refer to this service using as key the name of the interface that we will lokkup into
the Zookeeper registry to find it and get locally a proxy obect !

<reference id="myService" interface="org.fusesource.fabric.example.dosgi.Service" availability="optional"/>

<camelContext id="camel" trace="false" xmlns="http://camel.apache.org/schema/blueprint">

  <route id="fabric-client">
    <from uri="timer://foo?fixedRate=true&amp;period=10000"/>
    <setBody>
        <constant>Karaf Zookeeper server</constant>
    </setBody>
    <bean ref="myService" method="messageFrom"/>
    <log message=">>> Response from : ${body}"/>
  </route>

</camelContext>


COMPILING
=========
cd fabric-examples/fabric-camel-dosgi
mvn clean install

RUNNING
=======
1) Before you run Karaf you might like to set these environment variables...

    export JAVA_PERM_MEM=64m
    export JAVA_MAX_PERM_MEM=512m

2) Download and install a fresh distribution of FuseESB enterprise or Fabric 7.0

And run the following command in the console

3) Initialize a local Fabric

    fabric:create

4) Create a profile for the distributed service provider

    fabric:profile-create --parents dosgi dosgi-provider
    fabric:profile-edit --repositories mvn:org.fusesource.fabric.fabric-examples.fabric-camel-dosgi/features/${project.version}/xml/features dosgi-provider
    fabric:profile-edit --features fabric-example-dosgi dosgi-provider

5) Create a profile for the distributed service consumer

    fabric:profile-create --parents dosgi dosgi-camel
    fabric:profile-edit --repositories mvn:org.fusesource.fabric.fabric-examples.fabric-camel-dosgi/features/${project.version}/xml/features dosgi-camel
    fabric:profile-edit --features fabric-example-camel-dosgi dosgi-camel

6) Create a container and assign it the dosgi-provider profile

    fabric:container create --profile dosgi-provider root provider

7) Create a container and assign it the dosgi-provider profile

    fabric:container create --profile dosgi-camel root dosgi-camel

8) Check that the consumer routes and see the route info of consumer

shell:command-watch fabric:container-connect dosgi-camel camel:route-info fabric-client

The command above will automatically refresh the output every second.

Enjoy!
