Fuse 6 is no longer supported
As of February 2025, Red Hat Fuse 6 is no longer supported. If you are using Fuse 6, please upgrade to Red Hat build of Apache Camel.Chapter 9. Enabling High Availability in Fuse Fabric
Abstract
When all of your servers and clients are deployed within the same fabric, you can use an alternative mechanism for implementing high availability cluster, which works by exploiting the fabric registry. Because all the parts of the application must be deployed on the same fabric, this mechanism is suitable for deployment on a LAN.
9.1. Load Balancing Cluster Copy linkLink copied to clipboard!
Copy linkLink copied to clipboard!
9.1.1. Introduction to Load Balancing Copy linkLink copied to clipboard!
Copy linkLink copied to clipboard!
Overview Copy linkLink copied to clipboard!
Copy linkLink copied to clipboard!
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.
Fuse Fabric Copy linkLink copied to clipboard!
Copy linkLink copied to clipboard!
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).
Load-balancing cluster Copy linkLink copied to clipboard!
Copy linkLink copied to clipboard!
Figure 9.1, “Fabric Load Balancing for Apache CXF” gives an overview of the fabric load balancing mechanism for Apache CXF endpoints.
Figure 9.1. Fabric Load Balancing for Apache CXF
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.
FabricLoadBalancerFeature Copy linkLink copied to clipboard!
Copy linkLink copied to clipboard!
The fabric load balancer feature is implemented by the following class:
org.fusesource.fabric.cxf.FabricLoadBalancerFeature
org.fusesource.fabric.cxf.FabricLoadBalancerFeature
The
FabricLoadBalancerFeature
class exposes the following bean properties:
-
fabricPath
- This 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. -
zkClient
- A proxy reference to the OSGi service exposed by the fabric agent (of type,
org.linkedin.zookeeper.client.IZKClient
). -
maximumConnectionTimeout
- The maximum length of time to attempt to connect to the fabric agent, specified in milliseconds. The default is 10000 (10 seconds).
-
connectionRetryTime
- How long to wait between connection attempts, specified in milliseconds. The default is 100.
-
loadBalanceStrategy
- By implementing a bean of type
org.fusesource.fabric.cxf.LoadBalanceStrategy
and setting this property, you can customise the load balancing algorithm used by the load balancing feature.
Prerequisites Copy linkLink copied to clipboard!
Copy linkLink copied to clipboard!
To use the fabric load balancer feature in your application, your project must satisfy the following prerequisites:
Maven dependency Copy linkLink copied to clipboard!
Copy linkLink copied to clipboard!
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>6.0.0.redhat-024</version> </dependency>
<dependency>
<groupId>org.fusesource.fabric</groupId>
<artifactId>fabric-cxf</artifactId>
<version>6.0.0.redhat-024</version>
</dependency>
OSGi package import Copy linkLink copied to clipboard!
Copy linkLink copied to clipboard!
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:
Fabric deployment Copy linkLink copied to clipboard!
Copy linkLink copied to clipboard!
When you come to deploy your application into a Red Hat JBoss Fuse container, you must deploy it into a fabric. The fabric load balancer feature is not supported in a standalone container.
Required feature Copy linkLink copied to clipboard!
Copy linkLink copied to clipboard!
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:
JBossFuse:karaf@root> profile-edit -f fabric-cxf cxf-lb-server
JBossFuse:karaf@root> profile-edit -f fabric-cxf cxf-lb-server
9.1.2. Configure the Server Copy linkLink copied to clipboard!
Copy linkLink copied to clipboard!
Overview Copy linkLink copied to clipboard!
Copy linkLink copied to clipboard!
To configure a WS server to use fabric load balancing, you must configure a fabric load balancer feature and install it in the default Apache CXF bus instance. This section describes how to configure the load balancer feature in Spring XML and in blueprint XML.
Prerequisites Copy linkLink copied to clipboard!
Copy linkLink copied to clipboard!
For the basic prerequisites to build a fabric load-balancing WS server, see the section called “Prerequisites”.
Spring XML Copy linkLink copied to clipboard!
Copy linkLink copied to clipboard!
The following fragment from a Spring XML file shows how to add the fabric load balancer feature,
FabricLoadBalancerFeature
, to an Apache CXF bus. Any Apache CXF endpoints subsequently created on this bus will automatically have the load-balancer feature enabled.
The following beans are used to install the fabric load-balancer feature:
IZKClient
OSGi service reference- The
IZKClient
reference is a proxy of the local fabric agent, which it accesses through theorg.linkedin.zookeeper.client.IZKClient
interface. This reference is needed in order to integrate the load balancer feature with the underlying fabric. FabricLoadBalancerFeature
bean- The
FabricLoadBalancerFeature
bean is initialised with the following properties:-
zkClient
- A reference to the fabric agent proxy,
IZKClient
. -
fabricPath
- The path of a node in the fabric registry, where the cluster data is stored (for example, the addresses of the endpoints in the load-balancing cluster). The node path is specified relative to the base node,
/fabric/cxf/endpoints
.
-
- Apache CXF bus
- The
cxfcore:bus
element installs the fabric load balancer feature in the default bus instance.
Blueprint XML Copy linkLink copied to clipboard!
Copy linkLink copied to clipboard!
The following fragment from a blueprint XML file shows how to add the fabric load balancer feature,
FabricLoadBalancerFeature
, to an Apache CXF bus. Any Apache CXF endpoints subsequently created on this bus will automatically have the load-balancer feature enabled.
The following beans are used to install the fabric load-balancer feature:
IZKClient
reference- The
IZKClient
reference is a proxy of the local fabric agent, which it accesses through theorg.linkedin.zookeeper.client.IZKClient
interface. This reference is needed in order to integrate the load balancer feature with the underlying fabric. FabricLoadBalancerFeature
bean- The
FabricLoadBalancerFeature
bean is initialised with the following properties:-
zkClient
- A reference to the fabric agent proxy,
IZKClient
. -
fabricPath
- The path of a node in the fabric registry, where the cluster data is stored (for example, the addresses of the endpoints in the load-balancing cluster). The node path is specified relative to the base node,
/fabric/cxf/endpoints
.
-
- Apache CXF bus
- The
cxf:bus
element installs the fabric load balancer feature in the default bus instance.
Example using Spring XML Copy linkLink copied to clipboard!
Copy linkLink copied to clipboard!
Example 9.1, “WS Server with Fabric Load Balancer Feature” shows a complete Spring XML example of a WS endpoint configured to use the fabric load balancing feature.
Example 9.1. WS Server with Fabric Load Balancer Feature
The preceding Spring XML configuration consists of the following main sections:
- Setting up OSGi Configuration Admin—the
osgix:cm-properties
element and thectx:property-placeholder
element set up the OSGi Configuration Admin service, enabling you to substitute the WS endpoint's IP port number using the placeholder,${portNumber}
.Use of the OSGi Configuration Admin service is optional, but it provides a convenient way of creating a cluster of WS servers listening on different ports. With the configuration shown here, you can deploy the same server bundle into different container instances, using the OSGi Configuration Admin service to customise the IP port of each deployed server instance. - Creating the WS endpoint—create the WS endpoint in the usual way, using the
jaxws:endpoint
element. By default, this endpoint is automatically associated with the default bus instance, which has load balancing enabled. The only unusual aspect of this endpoint definition is that the OSGi Configuration Admin service is used to define the port number in the endpoint's address (through the${portNumber}
placeholder). - Enabling the fabric load balancing feature—the fabric load balancing feature is installed in the default bus instance, as previously described. In this example, the
fabricPath
property is set to the value,demo/lb
.
Creating fabric profiles for the example Copy linkLink copied to clipboard!
Copy linkLink copied to clipboard!
To deploy the WS endpoint in a fabric, you need to create the appropriate profiles. Because you want to create a cluster of WS endpoints, it makes sense to define multiple profiles, where each WS endpoint gets its own profile. For example, you could define the following set of profiles for deployment:
-
cxf-lb-server
- A base profile, containing details common to all of the cluster endpoints.
-
cxf-lb-server-8185
- A profile that inherits from
cxf-lb-server
and sets theportNumber
property to 8185. -
cxf-lb-server-8186
- A profile that inherits from
cxf-lb-server
and sets theportNumber
property to 8186.
Assuming that the example server bundle (containing the WS endpoint implementation) is stored in the local Maven repository and has the Maven coordinates,
org.fusesource.example/cxf-lb-server/1.0-SNAPSHOT
, you can create the cxf-lb-server
base profile by entering the following console commands:
JBossFuse:karaf@root> profile-create --parents cxf cxf-lb-server JBossFuse:karaf@root> profile-edit -f fabric-cxf cxf-lb-server JBossFuse:karaf@root> profile-edit -b mvn:org.fusesource.example/cxf-lb-server/1.0-SNAPSHOT cxf-lb-server
JBossFuse:karaf@root> profile-create --parents cxf cxf-lb-server
JBossFuse:karaf@root> profile-edit -f fabric-cxf cxf-lb-server
JBossFuse:karaf@root> profile-edit -b mvn:org.fusesource.example/cxf-lb-server/1.0-SNAPSHOT cxf-lb-server
You can then create the
cxf-lb-server-8185
profile and the cxf-lb-server-8186
profile as follows:
JBossFuse:karaf@root> profile-create --parents cxf-lb-server cxf-lb-server-8185 JBossFuse:karaf@root> profile-create --parents cxf-lb-server cxf-lb-server-8186 JBossFuse:karaf@root> profile-edit -p org.fusesource.example.fabric.lb/portNumber=8185 cxf-lb-server-8185 JBossFuse:karaf@root> profile-edit -p org.fusesource.example.fabric.lb/portNumber=8186 cxf-lb-server-8186
JBossFuse:karaf@root> profile-create --parents cxf-lb-server cxf-lb-server-8185
JBossFuse:karaf@root> profile-create --parents cxf-lb-server cxf-lb-server-8186
JBossFuse:karaf@root> profile-edit -p org.fusesource.example.fabric.lb/portNumber=8185 cxf-lb-server-8185
JBossFuse:karaf@root> profile-edit -p org.fusesource.example.fabric.lb/portNumber=8186 cxf-lb-server-8186
The
cxf-lb-server-8185
profile and the cxf-lb-server-8186
profile are now ready to be deployed to the container of your choice, using the fabric:container-change-profile
command.
9.1.3. Configure the Client Copy linkLink copied to clipboard!
Copy linkLink copied to clipboard!
Overview Copy linkLink copied to clipboard!
Copy linkLink copied to clipboard!
To configure a WS client to use fabric load balancing, you must install the fabric load balancer feature directly in the client proxy instance. This section describes how to configure the load balancer feature in Spring XML, blueprint XML, and by programming in Java.
Prerequisites Copy linkLink copied to clipboard!
Copy linkLink copied to clipboard!
For the basic prerequisites to build a fabric load-balancing WS client, see the section called “Prerequisites”.
Spring XML Copy linkLink copied to clipboard!
Copy linkLink copied to clipboard!
The following fragment from a Spring XML file shows how to add the fabric load balancer feature,
FabricLoadBalancerFeature
, directly into a WS client proxy instance.
The fabric load balancer feature is installed directly into the WS client proxy by inserting it as a child of the
jaxws:features
element (or, as in this case, by inserting a bean reference to the actual instance). The following beans are used to initialise the fabric load-balancer feature:
IZKClient
OSGi service reference- The
IZKClient
reference is a proxy of the local fabric agent, which it accesses through theorg.linkedin.zookeeper.client.IZKClient
interface. This reference is needed in order to integrate the load balancer feature with the underlying fabric. FabricLoadBalancerFeature
bean- The
FabricLoadBalancerFeature
bean is initialised with the following properties:-
zkClient
- A reference to the fabric agent proxy,
IZKClient
. -
fabricPath
- The path of a node in the fabric registry, where the cluster data is stored (for example, the addresses of the endpoints in the load-balancing cluster). The node path is specified relative to the base node,
/fabric/cxf/endpoints
.
-
Blueprint XML Copy linkLink copied to clipboard!
Copy linkLink copied to clipboard!
The following fragment from a blueprint XML file shows how to add the fabric load balancer feature,
FabricLoadBalancerFeature
, directly into a WS client proxy instance.
The fabric load balancer feature is installed directly into the WS client proxy by inserting it as a child of the
jaxws:features
element (or, as in this case, by inserting a bean reference to the actual instance). The following beans are used to initialise the fabric load-balancer feature:
IZKClient
reference- The
IZKClient
reference is a proxy of the local fabric agent, which it accesses through theorg.linkedin.zookeeper.client.IZKClient
interface. This reference is needed in order to integrate the load balancer feature with the underlying fabric. FabricLoadBalancerFeature
bean- The
FabricLoadBalancerFeature
bean is initialised with the following properties:-
zkClient
- A reference to the fabric agent proxy,
IZKClient
. -
fabricPath
- The path of a node in the fabric registry, where the cluster data is stored (for example, the addresses of the endpoints in the load-balancing cluster). The node path is specified relative to the base node,
/fabric/cxf/endpoints
.
-
Java Copy linkLink copied to clipboard!
Copy linkLink copied to clipboard!
As an alternative to using XML configuration, you can enable the fabric load balancing feature on the client side by programming directly in Java. The following example shows how to enable fabric load balancing on a proxy for the
Hello
Web service.
In this example, the
fabricPath
property is set to the value, demo/lb
(which matches the example value used by the server in Example 9.1, “WS Server with Fabric Load Balancer Feature”).
The address that the client proxy accesses is set to a dummy value,
http://dummyaddress
, because this value is not used. When the client is initialized, the load balancer feature substitutes the address value retrieved from the demo/lb
node of the fabric registry.
Example using Spring XML Copy linkLink copied to clipboard!
Copy linkLink copied to clipboard!
Example 9.2, “Client Proxy with Fabric Load Balancer Feature” shows a detailed Spring XML example of how to configure a WS client proxy with the fabric load balancer feature.
Example 9.2. Client Proxy with Fabric Load Balancer Feature
Creating a fabric profile for the client Copy linkLink copied to clipboard!
Copy linkLink copied to clipboard!
To deploy the WS client in a fabric, you need to create a profile for it. Assuming that the example client bundle is stored in the local Maven repository and has the Maven coordinates,
org.fusesource.example/cxf-lb-client/1.0-SNAPSHOT
, you can create the cxf-lb-client
profile by entering the following console commands:
JBossFuse:karaf@root> profile-create --parents cxf cxf-lb-client JBossFuse:karaf@root> profile-edit -f fabric-cxf cxf-lb-client JBossFuse:karaf@root> profile-edit -b mvn:org.fusesource.example/cxf-lb-client/1.0-SNAPSHOT cxf-lb-client
JBossFuse:karaf@root> profile-create --parents cxf cxf-lb-client
JBossFuse:karaf@root> profile-edit -f fabric-cxf cxf-lb-client
JBossFuse:karaf@root> profile-edit -b mvn:org.fusesource.example/cxf-lb-client/1.0-SNAPSHOT cxf-lb-client
The
cxf-lb-client
profile is now ready to be deployed to the container of your choice, using the fabric:container-change-profile
command.