Fabric8 Documentation

CXF Fabric

Like the Camel Fabric the CXF Fabric makes it easy to expose physical web services into the Runtime Registry so that clients can just bind to the logical name of the service and at runtime locate and load balance across the running implementations.

Basically, your CXF endpoint will know nothing about the Fabric runtime, and you just need to configure the FabricLoadBalanceFeature with the ZKClientFactoryBean and set the feature into the bus, the FabricLoadBalanceFeature will interact with Fabric runtime automatically.

You can configure the fabricPath of the FabricLoadBalancerFeature for the CXF server and CXF client to use.

<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
         http://cxf.apache.org/core http://cxf.apache.org/schemas/core.xsd">

  <bean id="zkClient" class="io.fabric8.zookeeper.spring.ZKClientFactoryBean">
    <property name="timeoutText" value="30s"/>
    <property name="connectString" value="localhost:2181"/>

  <bean id="fabicLoadBalancerFeature" class="io.fabric8.cxf.FabricLoadBalancerFeature">
      <property name="zkClient" ref="zkClient" />
      <property name="fabricPath" value="simple" />
  <!-- configure the feature on the bus -->
      <ref bean="fabicLoadBalancerFeature" />


Exposing a CXF endpoint into the fabric

// You just need to make sure the bus is configured with the FabricLoadBalanceFeature
ServerFactoryBean factory = new ServerFactoryBean();
factory.setServiceBean(new HelloImpl());

Here you can use the CXF normal code to publish the CXF service, but you need to make sure the FabricLoadBalancerFeature is registered into the bus that you service will be published.

Invoking a CXF fabric endpoint

ClientProxyFactoryBean clientFactory = new ClientProxyFactoryBean();
// The address is not the actual address that the client will access
List<AbstractFeature> features = new ArrayList<AbstractFeature>();
Feature feature = new FabricFailOverFeature();
// you need setting the feature with zkClient and fabricPath to load the server addresses
// add the instance of FabricLoadBalancerFeature into features list
// we need to setup the feature on the clientfactory
Hello hello = clientFactory.create(Hello.class);
String response = hello.sayHello();

For the CXF client, you just need to set the FabricLoadBalancerFeature directly into the clientFactory. The FabricLoadBalancerFeature will pick a real service physical address for the Fabric service registry for the client to use.