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.Ce contenu n'est pas disponible dans la langue sélectionnée.
Chapter 9. Enabling High Availability in Fuse Fabric
Abstract
9.1. Load Balancing Cluster Copier lienLien copié sur presse-papiers!
9.1.1. Introduction to Load Balancing Copier lienLien copié sur presse-papiers!
Overview Copier lienLien copié sur presse-papiers!
Fuse Fabric Copier lienLien copié sur presse-papiers!
Load-balancing cluster Copier lienLien copié sur presse-papiers!
Figure 9.1. Fabric Load Balancing for Apache CXF
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.
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 Copier lienLien copié sur presse-papiers!
org.fusesource.fabric.cxf.FabricLoadBalancerFeature
org.fusesource.fabric.cxf.FabricLoadBalancerFeature
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.LoadBalanceStrategyand setting this property, you can customise the load balancing algorithm used by the load balancing feature.
Prerequisites Copier lienLien copié sur presse-papiers!
Maven dependency Copier lienLien copié sur presse-papiers!
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 Copier lienLien copié sur presse-papiers!
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 Copier lienLien copié sur presse-papiers!
Required feature Copier lienLien copié sur presse-papiers!
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 Copier lienLien copié sur presse-papiers!
Overview Copier lienLien copié sur presse-papiers!
Prerequisites Copier lienLien copié sur presse-papiers!
Spring XML Copier lienLien copié sur presse-papiers!
FabricLoadBalancerFeature, to an Apache CXF bus. Any Apache CXF endpoints subsequently created on this bus will automatically have the load-balancer feature enabled.
IZKClientOSGi service reference- The
IZKClientreference is a proxy of the local fabric agent, which it accesses through theorg.linkedin.zookeeper.client.IZKClientinterface. This reference is needed in order to integrate the load balancer feature with the underlying fabric. FabricLoadBalancerFeaturebean- The
FabricLoadBalancerFeaturebean 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:buselement installs the fabric load balancer feature in the default bus instance.
Blueprint XML Copier lienLien copié sur presse-papiers!
FabricLoadBalancerFeature, to an Apache CXF bus. Any Apache CXF endpoints subsequently created on this bus will automatically have the load-balancer feature enabled.
IZKClientreference- The
IZKClientreference is a proxy of the local fabric agent, which it accesses through theorg.linkedin.zookeeper.client.IZKClientinterface. This reference is needed in order to integrate the load balancer feature with the underlying fabric. FabricLoadBalancerFeaturebean- The
FabricLoadBalancerFeaturebean 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:buselement installs the fabric load balancer feature in the default bus instance.
Example using Spring XML Copier lienLien copié sur presse-papiers!
Example 9.1. WS Server with Fabric Load Balancer Feature
- Setting up OSGi Configuration Admin—the
osgix:cm-propertieselement and thectx:property-placeholderelement 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:endpointelement. 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
fabricPathproperty is set to the value,demo/lb.
Creating fabric profiles for the example Copier lienLien copié sur presse-papiers!
-
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-serverand sets theportNumberproperty to 8185. -
cxf-lb-server-8186 - A profile that inherits from
cxf-lb-serverand sets theportNumberproperty to 8186.
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
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
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 Copier lienLien copié sur presse-papiers!
Overview Copier lienLien copié sur presse-papiers!
Prerequisites Copier lienLien copié sur presse-papiers!
Spring XML Copier lienLien copié sur presse-papiers!
FabricLoadBalancerFeature, directly into a WS client proxy instance.
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:
IZKClientOSGi service reference- The
IZKClientreference is a proxy of the local fabric agent, which it accesses through theorg.linkedin.zookeeper.client.IZKClientinterface. This reference is needed in order to integrate the load balancer feature with the underlying fabric. FabricLoadBalancerFeaturebean- The
FabricLoadBalancerFeaturebean 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 Copier lienLien copié sur presse-papiers!
FabricLoadBalancerFeature, directly into a WS client proxy instance.
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:
IZKClientreference- The
IZKClientreference is a proxy of the local fabric agent, which it accesses through theorg.linkedin.zookeeper.client.IZKClientinterface. This reference is needed in order to integrate the load balancer feature with the underlying fabric. FabricLoadBalancerFeaturebean- The
FabricLoadBalancerFeaturebean 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 Copier lienLien copié sur presse-papiers!
Hello Web service.
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”).
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 Copier lienLien copié sur presse-papiers!
Example 9.2. Client Proxy with Fabric Load Balancer Feature
Creating a fabric profile for the client Copier lienLien copié sur presse-papiers!
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
cxf-lb-client profile is now ready to be deployed to the container of your choice, using the fabric:container-change-profile command.