How to avoid consuming a file from shared directory from multiple fuse server nodes configured in cluster using fabric master ?
Environment
- Red Hat JBoss Fuse
- 6.1.0
Issue
- 2 Fuse servers set on Active run into race condition
- 2 Fuse servers set to pick inbound files from a shared location. When the file come in, they are zipped and only one node is supposed to unzip and process the file
- A way to ensure that only a single consumer in a cluster consumes from a given endpoint using Master component from the camel route in fabric
- File reading in a clustered environment
Resolution
- The
Master componentprovides a way to ensure that only a single consumer in a cluster consumes from a given endpoint. - The
Master componentcan only be used in the context of afabric-enabledRed Hat JBoss Fuse container. You must ensure that thefabric-camelfeature is installed. - Steps to create a cluster
- If you do not already have a fabric, enter the following console command to create one
JBossFuse:karaf@root> fabric:create --wait-for-provisioning
- You just created the fabric on a clean installation of JBoss Fuse . In this case, the root container ought to include the jboss-fuse-full profile by default. You can check whether this is the case by entering the fabric:container-list console command, as follows:
JBossFuse:karaf@root> fabric:container-list
[id] [version] [connected] [profiles] [provision status]
root* 1.0 true fabric, fabric-ensemble-0000-1, jboss-fuse-full success
- Create the
master-exampleprofile, which will be used to deploy a simple Apache Camel route that uses theMaster component. Enter the following console command to create the profile:
JBossFuse:karaf@root> fabric:profile-create --parents default master-example
- Add the requisite
Karaffeatures to themaster-exampleprofile. Enter the following console commands:
fabric:profile-edit --features fabric-camel master-example
- Define the simple Camel route as a resource in the
master-exampleprofile. Invoke the built-in text editor to create a newcamelFile.xmlresource, as follows:
fabric:profile-edit --resource camelFile.xml master-example
- Copy and paste the following content into the built-in text editor:
<?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">
<reference id="curator" interface="org.apache.curator.framework.CuratorFramework"/>
<camelContext id="camel" xmlns="http://camel.apache.org/schema/blueprint">
<route>
<from uri="master:lockhandle:file:/home/kkakarla/Development/sample?delay=900"/>
<to uri="file:/home/kkakarla/Development"/>
<log message="Completed"/>
</route>
</camelContext>
</blueprint>
- To save and exit from the text editor, type Ctrl-S, Ctrl-X.
- Configure the
master-exampleprofile to deploy thecamelFile.xmlresource as anOSGi bundle. Enter the following console command to create a new entry in themaster-exampleagent properties:
fabric:profile-edit --bundles blueprint:profile:camelFile.xml master-example
- Create two new child containers, so that you can deploy the master-example profile as a cluster (one master and one slave). Enter the following console command:
fabric:container-create-child root child1
fabric:container-create-child root child2
- Now deploy both the master-example profile to each of the child containers, as follows:
fabric:container-change-profile child1 master-example
fabric:container-change-profile child2 master-example
This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.
Welcome! Check out the Getting Started with Red Hat page for quick tours and guides for common tasks.
