How to avoid consuming a file from shared directory from multiple fuse server nodes configured in cluster using fabric master ?

Solution Unverified - Updated -

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 component provides a way to ensure that only a single consumer in a cluster consumes from a given endpoint.
  • The Master component can only be used in the context of a fabric-enabled Red Hat JBoss Fuse container. You must ensure that the fabric-camel feature 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-example profile, which will be used to deploy a simple Apache Camel route that uses the Master component. Enter the following console command to create the profile:
JBossFuse:karaf@root> fabric:profile-create --parents default master-example
  • Add the requisite Karaf features to the master-example profile. Enter the following console commands:
fabric:profile-edit --features fabric-camel master-example
  • Define the simple Camel route as a resource in the master-example profile. Invoke the built-in text editor to create a new camelFile.xml resource, 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-example profile to deploy the camelFile.xml resource as an OSGi bundle. Enter the following console command to create a new entry in the master-example agent 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.

Close

Welcome! Check out the Getting Started with Red Hat page for quick tours and guides for common tasks.