The fabric load balancing mechanism exploits the fact that fabric provides a distributed fabric registry, which is accessible to all of the container in the fabric. This makes it possible to use the fabric registry as a discovery mechanism for locating WS endpoints in the fabric. By storing all of the endpoint addresses belonging to a particular cluster under the same registry node, any WS clients in the fabric can easily discover the location of the endpoints in the cluster.
A fabric is a distributed collection of containers that share a common database of configuration settings (the fabric registry). Every container in the fabric has a fabric agent deployed in it, which manages the container and redeploys applications to the container whenever a new profile is assigned to the container (a profile is the basic deployment unit in a fabric).
Figure 9.1 gives an overview of the fabric load balancing mechanism for Apache CXF endpoints.
In this example, two WS servers are created, with the URIs,
http://localhost:8185/Foo and http://localhost:8186/Foo. For
both of these servers, the load balancer feature is configured to store the cluster
endpoints under the path, demo/lb, in the fabric registry.
Now, when the WS client starts, it is configured to look up the cluster path,
demo/lb, in the fabric registry. Because the demo/lb path is
associated with multiple endpoint addresses, fabric implements a random load balancing
algorithm to choose one of the available URIs to connect to.
The fabric load balancer feature is implemented by the following class:
org.fusesource.fabric.cxf.FabricLoadBalancerFeature
The FabricLoadBalancerFeature class exposes the following bean
properties:
fabricPathThis property specifies a node in the fabric registry (specified relative to the base node,
/fabric/cxf/endpoints) that is used to store the data for a particular endpoint cluster.zkClientA proxy reference to the OSGi service exposed by the fabric agent (of type,
org.linkedin.zookeeper.client.IZKClient).maximumConnectionTimeoutThe maximum length of time to attempt to connect to the fabric agent, specified in milliseconds. The default is 10000 (10 seconds).
connectionRetryTimeHow long to wait between connection attempts, specified in milliseconds. The default is 100.
loadBalanceStrategyBy implementing a bean of type
org.fusesource.fabric.cxf.LoadBalanceStrategyand setting this property, you can customise the load balancing algorithm used by the load balancing feature.
To use the fabric load balancer feature in your application, your project must satisfy the following prerequisites:
The fabric load balancer feature requires the fabric-cxf Maven artifact.
Add the following dependency to your project's POM file:
<dependency>
<groupId>org.fusesource.fabric</groupId>
<artifactId>fabric-cxf</artifactId>
<version>7.0.2.fuse-097</version>
</dependency>If you are packaging your project as an OSGi bundle, you must add
org.fusesource.fabric.cxf to the list of imported packages. For example,
using the Maven bundle plug-in, you can specify this package import by adding
org.fusesource.fabric.cxf to the comma-separated list in the
Import-Package element, as follows:
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>2.2.0</version>
<extensions>true</extensions>
<configuration>
<instructions>
<Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
<Import-Package>
...
org.fusesource.fabric.cxf,
*
</Import-Package>
...
</instructions>
</configuration>
</plugin>When you come to deploy your application into a Fuse ESB Enterprise container, you must deploy it into a fabric. The fabric load balancer feature is not supported in a standalone container.
The fabric load balancer requires the fabric-cxf Apache Karaf feature to be
installed in the container. In the context of a fabric, this means you must add the
fabric-cxf feature to the relevant deployment profile. For example, if you
are using the cxf-lb-server profile to deploy a load-balancing WS server, you
can add the fabric-cxf feature by entering the following console
command:
karaf@root> profile-edit -f fabric-cxf cxf-lb-server









