Dieser Inhalt ist in der von Ihnen ausgewählten Sprache nicht verfügbar.
Chapter 29. Fabric Component
Abstract
Dependencies Link kopierenLink in die Zwischenablage kopiert!
fabric-camel feature is installed. If necessary, you can install it using the following console command:
karaf@root> features:install fabric-camel
fabric-camel feature is installed by including it in your feature definition. For example:
<?xml version="1.0" encoding="UTF-8"?>
<features>
<feature name="fabric-component-example">
<feature>fabric-camel</feature>
<bundle>URIforMyBundle</bundle>
<!-- Specify any other required bundles or features -->
...
</feature>
</features>
URI format Link kopierenLink in die Zwischenablage kopiert!
fabric:ClusterID[:PublishedURI[?Options]]
fabric:ClusterID:PublishedURI[?Options]
PublishedURI, is published in the fabric registry and associated with the ClusterId cluster. The options, Options, are used when creating the producer endpoint instance, but the options are not published with the PublishedURI in the fabric registry.
fabric:ClusterID
ClusterId, in the fabric registry to discover the URI to connect to.
URI options Link kopierenLink in die Zwischenablage kopiert!
- Server-only options—options that are applicable only to the server are applied to the server endpoint (consumer endpoint) at run time.
- Client-only options—options that are applicable only to the client are applied to the client endpoint (producer endpoint) at run time.
- Common options—options common to the client and the server are applied to both.
Use cases for fabric endpoints Link kopierenLink in die Zwischenablage kopiert!
Location discovery Link kopierenLink in die Zwischenablage kopiert!
Figure 29.1. Location Discovery through Fabric
jetty:http://0.0.0.0:9090. When this route is started, it automatically registers the Jetty URI in the fabric registry, under the cluster ID, foo.
fabric:foo. Now, when the client route starts, it automatically looks up the ID, foo, in the fabric registry and retrieves the associated Jetty endpoint URI. The client then creates a producer endpoint using the discovered Jetty URI and connects to the corresponding server port.
Load-balancing cluster Link kopierenLink in die Zwischenablage kopiert!
Figure 29.2. Load Balancing through Fabric
jetty:http://0.0.0.0:9090 and jetty:http://0.0.0.0:9191. Because these published URIs are both prefixed by fabric:foo:, both of the Jetty URIs are registered under the same cluster ID, foo, in the fabric registry.
foo, in the fabric registry. Because the foo ID is associated with multiple endpoint URIs, fabric implements a random load balancing algorithm to choose one of the available URIs. The client then creates a producer endpoint, using the chosen URI.
Auto-reconnect feature Link kopierenLink in die Zwischenablage kopiert!
Publishing an endpoint URI Link kopierenLink in die Zwischenablage kopiert!
PublishedURI, in the fabric registry, define a fabric endpoint with the publisher syntax, fabric:ClusterID:PublishedURI. Note that this syntax can only be used in a consumer endpoint (that is, an endpoint that appears in a from DSL command).
cheese. The route is a simply HTTP server that returns the constant message, Response from Zookeeper agent, in the body of the HTTP response.
Example 29.1. Publishing a URI
<?xml version="1.0" encoding="UTF-8"?>
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.osgi.org/xmlns/blueprint/v1.0.0
http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd">
<reference id="org.fusesource.fabric.zookeeper.IZKClient"
interface="org.fusesource.fabric.zookeeper.IZKClient" />
<camelContext id="camel" trace="false" xmlns="http://camel.apache.org/schema/blueprint">
<route id="fabric-server">
<from uri="fabric:cheese:jetty:http://0.0.0.0:9090/fabric"/>
<log message="Request received : ${body}"/>
<setHeader headerName="karaf.name">
<simple>${sys.karaf.name}</simple>
</setHeader>
<transform>
<simple>Response from Zookeeper agent</simple>
</transform>
</route>
</camelContext>
</blueprint>
- A reference to the
org.fusesource.fabric.zookeeper.IZKClientOSGi service is created using thereferenceelement. This reference is needed, because the Fabric component implicitly looks for anIZKClientobject in the bean registry and uses this object to connect to the underlying fabric.NoteTheIZKClientOSGi service is provided by the fabric agent. Hence, a fabric agent must already be installed and running in the container where the route is deployed. - The
fromDSL command defines the fabric URI,fabric:cheese:jetty:http://0.0.0.0:9090/fabric. At run time, this causes two things to happen:- The specified
jettyURI is published to the fabric registry under the cluster ID,cheese. - The Jetty endpoint is activated and used as the consumer endpoint of the route (just as if it had been specified without the
fabric:cheese:prefix).
src/main/resources/OSGI-INF/blueprint directory of a Maven project.
Looking up an endpoint URI Link kopierenLink in die Zwischenablage kopiert!
fabric:ClusterID. This syntax is used in a producer endpoint (for example, an endpoint that appears in a to DSL command).
cheese, in the fabric registry.
Example 29.2. Looking up a URI
<?xml version="1.0" encoding="UTF-8"?>
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.osgi.org/xmlns/blueprint/v1.0.0
http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd">
<reference id="org.fusesource.fabric.zookeeper.IZKClient"
interface="org.fusesource.fabric.zookeeper.IZKClient"/>
<camelContext id="camel" trace="false" xmlns="http://camel.apache.org/schema/blueprint">
<route id="fabric-client">
<from uri="timer://foo?fixedRate=true&period=10000"/>
<setBody>
<simple>Hello from Zookeeper server</simple>
</setBody>
<to uri="fabric:cheese"/>
<log message=">>> ${body} : ${header.karaf.name}"/>
</route>
</camelContext>
</blueprint>
org.fusesource.fabric.zookeeper.IZKClient OSGi service, which the Fabric component uses to connect to the underlying fabric.
src/main/resources/OSGI-INF/blueprint directory of a Maven project.
Load-balancing example Link kopierenLink in die Zwischenablage kopiert!
Example 29.3. Server Template for a Load-Balancing Cluster
<?xml version="1.0" encoding="UTF-8"?>
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.0.0"
xsi:schemaLocation="
http://www.osgi.org/xmlns/blueprint/v1.0.0
http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd">
<!-- osgi blueprint property placeholder -->
<cm:property-placeholder id="placeholder" persistent-id="fabricCamel">
<cm:default-properties>
<cm:property name="portNumber" value="8181"/>
</cm:default-properties>
</cm:property-placeholder>
<reference id="org.fusesource.fabric.zookeeper.IZKClient"
interface="org.fusesource.fabric.zookeeper.IZKClient" />
<camelContext id="camel" trace="false" xmlns="http://camel.apache.org/schema/blueprint">
<route id="fabric-server">
<from uri="fabric:cheese:jetty:http://0.0.0.0:{{portNumber}}/fabric"/>
<log message="Request received : ${body}"/>
<setHeader headerName="karaf.name">
<simple>${sys.karaf.name}</simple>
</setHeader>
<transform>
<simple>Response from Zookeeper agent</simple>
</transform>
</route>
</camelContext>
</blueprint>
fabricCamel persistent ID. A persistent ID in the OSGi Config Admin service identifies a collection of related property settings. After initializing the property placeholder, you can access any property values from the fabricCamel persistent ID using the syntax, {{PropName}}.
{{portNumber}}, at run time. At deploy time, you can specify the value of the portName property. For example, if using a custom feature, you could specify the property in the feature definition (see Add OSGi configurations to the feature). Alternatively, you can specify configuration properties when defining deployment profiles in the Fuse Management Console.
OSGi bundle plug-in configuration Link kopierenLink in die Zwischenablage kopiert!
Import-Package bundle header must be configured to import the following Java packages:
org.fusesource.fabric.zookeeper.spring
org.fusesource.fabric.zookeeper
Example 29.4. Maven Bundle Plug-In Configuration
<project ... >
...
<build>
<defaultGoal>install</defaultGoal>
<plugins>
...
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<extensions>true</extensions>
<configuration>
<instructions>
<Bundle-SymbolicName>${project.groupId}.${project.artifactId}</Bundle-SymbolicName>
<Import-Package>
org.fusesource.fabric.zookeeper.spring,
org.fusesource.fabric.zookeeper,
*
</Import-Package>
</instructions>
</configuration>
</plugin>
</plugins>
</build>
...
</project>